13.1 設定更改root密碼 13.2 串連mysql 13.3 mysql常用命令

來源:互聯網
上載者:User

標籤:13.1 設定更改root密碼 13.2

13.1 設定更改root密碼


[[email protected] init.d]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
[[email protected] init.d]# PATH=$PATH:/usr/local/mysql/bin
[[email protected] init.d]# vim /etc/profile
[[email protected] init.d]# source /etc/profile
[[email protected] init.d]# mysql -uroot
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.6.35 MySQL Community Server (GPL)
[[email protected] init.d]# mysqladmin -uroot password ‘martin.1‘
Warning: Using a password on the command line interface can be insecure.
[[email protected] init.d]# mysql -uroot
ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: NO)
[[email protected] init.d]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.6.35 MySQL Community Server (GPL)
知道root密碼,修改root密碼:
[[email protected] init.d]# mysqladmin -uroot -p‘martin.1‘ password ‘martin.2‘
Warning: Using a password on the command line interface can be insecure.

不知道root密碼的情況下修改root密碼:
修改/etc/my.cnf 第一行添加 skip-grant
重啟mysql服務 /etc/init.d/mysqld restart
mysql> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> select * from user where user=‘root‘;
mysql> update user set password=password(‘martinlinux‘) where user=‘root‘;
Query OK, 4 rows affected (0.02 sec)
Rows matched: 4 Changed: 4 Warnings: 0

13.2 串連mysql


[[email protected] ~]# mysql -uroot -p‘martinlinux‘ -h127.0.0.1 -P3306
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.6.35 MySQL Community Server (GPL)
[[email protected] ~]# mysql -uroot -p‘martinlinux‘ -S/tmp/mysql.sock
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
[[email protected] ~]# mysql -uroot -p‘martinlinux‘ -e "show databases"
Warning: Using a password on the command line interface can be insecure.
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+

13.3 mysql常用命令

建立庫 create database db1;
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| db1 |
| mysql |
| performance_schema |
| test |
+--------------------+
5 rows in set (0.01 sec)
建立表 use db1; create table t1(id int(4), name char(40));
mysql> show create table t1\G;
1. row
Table: t1
Create Table: CREATE TABLE t1 (
id int(4) DEFAULT NULL,
name char(40) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8
1 row in set (0.01 sec)

查看當前資料庫版本 select version();
mysql> select version();
+-----------+
| version() |
+-----------+
| 5.6.35 |
+-----------+
1 row in set (0.00 sec)

查看資料庫狀態 show status;

mysql> show status;
+-----------------------------------------------+-------------+
| Variable_name | Value |
+-----------------------------------------------+-------------+
| Aborted_clients | 0 |
| Aborted_connects | 4 |
| Binlog_cache_disk_use | 0 |
| Binlog_cache_use | 0 |
| Binlog_stmt_cache_disk_use | 0 |
| Binlog_stmt_cache_use | 0 |
| Bytes_received | 1634 |
| Bytes_sent | 69469 |

查看各參數 show variables; show variables like ‘max_connect%‘;
mysql> show variables like ‘max_connect%‘;
+--------------------+-------+
| Variable_name | Value |
+--------------------+-------+
| max_connect_errors | 100 |
| max_connections | 151 |
+--------------------+-------+
2 rows in set (0.00 sec)

修改參數 set global max_connect_errors=1000;
mysql> set global max_connect_errors = 1000;
Query OK, 0 rows affected (0.01 sec)

查看隊列 show processlist; show full processlist;
mysql> show processlist;
+----+------+-----------+------+---------+------+-------+------------------+
| Id | User | Host | db | Command | Time | State | Info |
+----+------+-----------+------+---------+------+-------+------------------+
| 10 | root | localhost | db1 | Query | 0 | init | show processlist |
+----+------+-----------+------+---------+------+-------+------------------+
1 row in set (0.01 sec)

mysql> show full processlist;
+----+------+-----------+------+---------+------+-------+-----------------------+
| Id | User | Host | db | Command | Time | State | Info |
+----+------+-----------+------+---------+------+-------+-----------------------+
| 10 | root | localhost | db1 | Query | 0 | init | show full processlist |
+----+------+-----------+------+---------+------+-------+-----------------------+
1 row in set (0.00 sec)

13.1 設定更改root密碼 13.2 串連mysql 13.3 mysql常用命令

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.