設(shè)置更改root密碼、連接mysql、mysql常用命令

目錄

一拷沸、設(shè)置更改root密碼
二旨椒、連接mysql
三、mysql常用命令

一堵漱、設(shè)置更改root密碼

  • 檢查mysql服務(wù)是否啟動
[root@minglinux-01 ~] ps aux |grep mysql
root        828  0.0  0.0 115640  1824 ?        S    03:15   0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data/mysql --pid-file=/data/mysql/minglinux-01.pid
mysql      1199  0.0 24.7 1320112 462216 ?      Sl   03:15   0:59 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=minglinux-01.err --pid-file=/data/mysql/minglinux-01.pid --socket=/tmp/mysql.sock --port=3306
root       6529  0.0  0.0 112724   984 pts/0    S+   21:34   0:00 grep --color=auto mysql
  • mysql啟動
[root@minglinux-01 ~] mysql
-bash: mysql: 未找到命令   //只單獨(dú)輸入一個mysql命令是不行的综慎,因?yàn)镸ysql相關(guān)命令在/usr/local/mysql/bin路徑下,但該路徑不在環(huán)境變量PATH中
[root@minglinux-01 ~] echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin
[root@minglinux-01 ~] export PATH=$PATH:/usr/local/mysql/bin/   //臨時生效勤庐,系統(tǒng)重啟后失效
[root@minglinux-01 ~] echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/usr/local/mysql/bin/
[root@minglinux-01 ~] echo "PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile       //永久生效
[root@minglinux-01 ~] source /etc/profile  
[root@minglinux-01 ~] mysql -uroot -p  //指定使用root用戶登錄mysql示惊,-p參數(shù)用于指定密碼。root用戶是MySQL自帶的管理員賬戶愉镰,默認(rèn)是沒有密碼的米罚。
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.39-log MySQL Community Server (GPL)

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>   
mysql> quit  //quit退出mysql
Bye
  • 給root用戶設(shè)定密碼
[root@minglinux-01 ~] mysqladmin -uroot password '123456'
Warning: Using a password on the command line interface can be insecure.  //警告明文密碼不安全
[root@minglinux-01 ~] mysql -uroot  //不指定密碼無法登錄,
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
[root@minglinux-01 ~] mysql -uroot -p'123456'
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
Server version: 5.6.39-log MySQL Community Server (GPL)

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 

輸入密碼時需要加-p選項(xiàng)丈探,后面可以直接跟密碼录择。-p選項(xiàng)后面不可以有空格,密碼可以不加單引號(但是密碼中有特殊字符時就會出問題碗降,所以最好還是加上單引號)隘竭。當(dāng)然,-p選項(xiàng)后面也可以不加密碼讼渊,以和用戶交互的方式輸入密碼动看。

  • 再次修改root用戶密碼
[root@minglinux-01 ~] mysqladmin -uroot -p'123456' password 'toor'
Warning: Using a password on the command line interface can be insecure.
[root@minglinux-01 ~] mysql -uroot -p'toor'
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 13
Server version: 5.6.39-log MySQL Community Server (GPL)

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 

  • 在不知道root密碼的情況下修改root密碼
    修改/etc/my.cnf配置文件,增加一行skip-grant
[root@minglinux-01 ~] vim /etc/my.cnf

  7 [mysqld]
  8 skip-grant   //忽略授權(quán)爪幻,即用戶登錄mysql時不需要密碼

[root@minglinux-01 ~] /etc/init.d/mysqld restart
Shutting down MySQL.. SUCCESS! 
Starting MySQL. SUCCESS! 
···
[root@minglinux-01 ~] mysql -uroot //無需密碼直接登錄
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.39-log MySQL Community Server (GPL)

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 
  • 通過修改mysql庫中的user表來修改root密碼
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+
4 rows in set (0.00 sec)

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; //user表這記錄了用戶名菱皆、密碼、權(quán)限等信息
mysql> select password from user;  //密碼信息是加密的字符串挨稿,這些加密的字符串由password函數(shù)生成仇轻,所以修改密碼時也需要password函數(shù)對密碼進(jìn)行加密
+-------------------------------------------+
| password                                  |
+-------------------------------------------+
| *9CFBBC772F3F6C106020035386DA5BBBF1249A11 |
|                                           |
|                                           |
|                                           |
|                                           |
|                                           |
+-------------------------------------------+
6 rows in set (0.00 sec)

mysql> update user set password=password('123456') where user='root'; //修改密碼為123456
Query OK, 4 rows affected (0.00 sec)
Rows matched: 4  Changed: 4  Warnings: 0

  • 測試
    刪除/etc/my.cnf中的skip-grant后重啟mysql再進(jìn)行測試
[root@minglinux-01 ~] vim /etc/my.cnf
[root@minglinux-01 ~] /etc/init.d/mysqld restart
Shutting down MySQL.. SUCCESS! 
Starting MySQL. SUCCESS! 
[root@minglinux-01 ~] mysql -uroot -p'123456'
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 1
Server version: 5.6.39-log MySQL Community Server (GPL)

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 

二、連接mysql

mysql -uroot -p123456 //連接本機(jī)
mysql -uroot -p123456 -h127.0.0.1 -P3306 //指定IP和端口號遠(yuǎn)程連接
mysql -uroot -p123456 -S/tmp/mysql.sock //Socket連接
mysql -uroot -p123456 -e ''show databases'' //連接后執(zhí)行操作奶甘,常用于shell腳本

[root@minglinux-01 ~] mysql -uroot -p123456 -e 'show databases' 
Warning: Using a password on the command line interface can be insecure.
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+

三篷店、mysql常用命令

  • 查詢庫 show databases
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+
4 rows in set (0.00 sec)
  • 切換庫 use mysql
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
  • 查看庫里的表 show tables
mysql> show tables;
+---------------------------+
| Tables_in_mysql           |
+---------------------------+
| columns_priv              |
| db                        |
| event                     |
| func                      |
| general_log               |
| help_category             |
| help_keyword              |
| help_relation             |
| help_topic                |
| innodb_index_stats        |
| innodb_table_stats        |
| ndb_binlog_index          |
| plugin                    |
| proc                      |
| procs_priv                |
| proxies_priv              |
| servers                   |
| slave_master_info         |
| slave_relay_log_info      |
| slave_worker_info         |
| slow_log                  |
| tables_priv               |
| time_zone                 |
| time_zone_leap_second     |
| time_zone_name            |
| time_zone_transition      |
| time_zone_transition_type |
| user                      |
+---------------------------+
28 rows in set (0.00 sec)
  • 查看表里的字段 desc tb_name
mysql> desc user;
+------------------------+-----------------------------------+------+-----+-----------------------+-------+
| Field                  | Type                              | Null | Key | Default               | Extra |
+------------------------+-----------------------------------+------+-----+-----------------------+-------+
| Host                   | char(60)                          | NO   | PRI |                       |       |
| User                   | char(16)                          | NO   | PRI |                       |       |
| Password               | char(41)                          | NO   |     |                       |       |
| Select_priv            | enum('N','Y')                     | NO   |     | N                     |       |
| Insert_priv            | enum('N','Y')                     | NO   |     | N                     |       |
| Update_priv            | enum('N','Y')                     | NO   |     | N                     |       |
| Delete_priv            | enum('N','Y')                     | NO   |     | N                     |       |
| Create_priv            | enum('N','Y')                     | NO   |     | N                     |       |
| Drop_priv              | enum('N','Y')                     | NO   |     | N                     |       |
| Reload_priv            | enum('N','Y')                     | NO   |     | N                     |       |
| Shutdown_priv          | enum('N','Y')                     | NO   |     | N                     |       |
| Process_priv           | enum('N','Y')                     | NO   |     | N                     |       |
| File_priv              | enum('N','Y')                     | NO   |     | N                     |       |
| Grant_priv             | enum('N','Y')                     | NO   |     | N                     |       |
| References_priv        | enum('N','Y')                     | NO   |     | N                     |       |
| Index_priv             | enum('N','Y')                     | NO   |     | N                     |       |
| Alter_priv             | enum('N','Y')                     | NO   |     | N                     |       |
| Show_db_priv           | enum('N','Y')                     | NO   |     | N                     |       |
| Super_priv             | enum('N','Y')                     | NO   |     | N                     |       |
| Create_tmp_table_priv  | enum('N','Y')                     | NO   |     | N                     |       |
| Lock_tables_priv       | enum('N','Y')                     | NO   |     | N                     |       |
| Execute_priv           | enum('N','Y')                     | NO   |     | N                     |       |
| Repl_slave_priv        | enum('N','Y')                     | NO   |     | N                     |       |
| Repl_client_priv       | enum('N','Y')                     | NO   |     | N                     |       |
| Create_view_priv       | enum('N','Y')                     | NO   |     | N                     |       |
| Show_view_priv         | enum('N','Y')                     | NO   |     | N                     |       |
| Create_routine_priv    | enum('N','Y')                     | NO   |     | N                     |       |
| Alter_routine_priv     | enum('N','Y')                     | NO   |     | N                     |       |
| Create_user_priv       | enum('N','Y')                     | NO   |     | N                     |       |
| Event_priv             | enum('N','Y')                     | NO   |     | N                     |       |
| Trigger_priv           | enum('N','Y')                     | NO   |     | N                     |       |
| Create_tablespace_priv | enum('N','Y')                     | NO   |     | N                     |       |
| ssl_type               | enum('','ANY','X509','SPECIFIED') | NO   |     |                       |       |
| ssl_cipher             | blob                              | NO   |     | NULL                  |       |
| x509_issuer            | blob                              | NO   |     | NULL                  |       |
| x509_subject           | blob                              | NO   |     | NULL                  |       |
| max_questions          | int(11) unsigned                  | NO   |     | 0                     |       |
| max_updates            | int(11) unsigned                  | NO   |     | 0                     |       |
| max_connections        | int(11) unsigned                  | NO   |     | 0                     |       |
| max_user_connections   | int(11) unsigned                  | NO   |     | 0                     |       |
| plugin                 | char(64)                          | YES  |     | mysql_native_password |       |
| authentication_string  | text                              | YES  |     | NULL                  |       |
| password_expired       | enum('N','Y')                     | NO   |     | N                     |       |
+------------------------+-----------------------------------+------+-----+-----------------------+-------+
43 rows in set (0.00 sec)

  • 查看建表語句 show create table tb_name\G
mysql> show create table user\G;
*************************** 1. row ***************************
       Table: user
Create Table: CREATE TABLE `user` (
  `Host` char(60) COLLATE utf8_bin NOT NULL DEFAULT '',
  `User` char(16) COLLATE utf8_bin NOT NULL DEFAULT '',
  `Password` char(41) CHARACTER SET latin1 COLLATE latin1_bin NOT NULL DEFAULT '',
  `Select_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
  `Insert_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
  `Update_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
  `Delete_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
  `Create_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
  `Drop_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
  `Reload_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
  `Shutdown_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
  `Process_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
  `File_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
  `Grant_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
  `References_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
  `Index_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
  `Alter_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
  `Show_db_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
  `Super_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
  `Create_tmp_table_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
  `Lock_tables_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
  `Execute_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
  `Repl_slave_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
  `Repl_client_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
  `Create_view_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
  `Show_view_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
  `Create_routine_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
  `Alter_routine_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
  `Create_user_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
  `Event_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
  `Trigger_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
  `Create_tablespace_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
  `ssl_type` enum('','ANY','X509','SPECIFIED') CHARACTER SET utf8 NOT NULL DEFAULT '',
  `ssl_cipher` blob NOT NULL,
  `x509_issuer` blob NOT NULL,
  `x509_subject` blob NOT NULL,
  `max_questions` int(11) unsigned NOT NULL DEFAULT '0',
  `max_updates` int(11) unsigned NOT NULL DEFAULT '0',
  `max_connections` int(11) unsigned NOT NULL DEFAULT '0',
  `max_user_connections` int(11) unsigned NOT NULL DEFAULT '0',
  `plugin` char(64) COLLATE utf8_bin DEFAULT 'mysql_native_password',
  `authentication_string` text COLLATE utf8_bin,
  `password_expired` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
  PRIMARY KEY (`Host`,`User`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='Users and global privileges'
1 row in set (0.00 sec)

ERROR: 
No query specified

命令加\G的目的是讓列出來的結(jié)果豎排顯示,這樣看起來更清晰甩十。

  • 查看當(dāng)前用戶 select user()
mysql> select user();
+----------------+
| user()         |
+----------------+
| root@localhost |  
+----------------+
1 row in set (0.00 sec)

[root@minglinux-01 ~] mysql -uroot -p123456 -h192.168.162.130 //
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 9
Server version: 5.6.39-log MySQL Community Server (GPL)

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> select user();
+-------------------+
| user()            |
+-------------------+
| root@minglinux-01 |   //這里ip地址192.168.162.130被反解析到主機(jī)名minglinux-01
+-------------------+
1 row in set (0.00 sec)

  • 查看當(dāng)前使用的數(shù)據(jù)庫 select databsase()
mysql> select database();
+------------+
| database() |
+------------+
| NULL       |    //當(dāng)前為NULL
+------------+
1 row in set (0.00 sec)

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> use mysql;
Database changed
mysql> select database();
+------------+
| database() |
+------------+
| mysql      |
+------------+
1 row in set (0.00 sec)

  • 創(chuàng)建庫 create database db1
mysql> create database db1;
Query OK, 1 row affected (0.00 sec)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| db1                |
| mysql              |
| performance_schema |
| test               |
+--------------------+
5 rows in set (0.00 sec)

  • 創(chuàng)建表 use db1; create table t1(id int(4), name char(40))
mysql> use db1;
Database changed
mysql> create table t1(`id` int(4), `name` char(40));
Query OK, 0 rows affected (0.01 sec)

mysql> show tables;
+---------------+
| Tables_in_db1 |
+---------------+
| t1            |
+---------------+
1 row in set (0.00 sec)
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=latin1
1 row in set (0.00 sec)

ERROR: 
No query specified
mysql> drop table t1;
Query OK, 0 rows affected (0.00 sec)

mysql> create table t1(`id` int(4),`name` char(40)) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Query OK, 0 rows affected (0.01 sec)

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  //字符集已改成utf8
1 row in set (0.00 sec)

ERROR: 
No query specified

  • 查看當(dāng)前數(shù)據(jù)庫版本 select version()
mysql> select version();
+------------+
| version()  |
+------------+
| 5.6.39-log |
+------------+
1 row in set (0.00 sec)
  • 查看數(shù)據(jù)庫狀態(tài) show status
mysql> show status;
+-----------------------------------------------+-------------+
| Variable_name                                 | Value       |
+-----------------------------------------------+-------------+
| Aborted_clients                               | 0           |
| Aborted_connects                              | 2           |
| Binlog_cache_disk_use                         | 0           |
| Binlog_cache_use                              | 0           |
| Binlog_stmt_cache_disk_use                    | 0           |
| Binlog_stmt_cache_use                         | 4           |
| Bytes_received                                | 1246        |
| Bytes_sent                                    | 22400       |
| Com_admin_commands                            | 0           |
| Com_assign_to_keycache                        | 0           |
| Com_alter_db                                  | 0           |
| Com_alter_db_upgrade                          | 0           |
| Com_alter_event                               | 0           |
| Com_alter_function                            | 0           |
| Com_alter_procedure                           | 0           |
| Com_alter_server                              | 0           |
| Com_alter_table                               | 0           |
| Com_alter_tablespace                          | 0           |
| Com_alter_user                                | 0           |
| Com_analyze                                   | 0           |
| Com_begin                                     | 0           |
| Com_binlog                                    | 0           |
| Com_call_procedure                            | 0           |
| Com_change_db                                 | 3           |
···
···
+-----------------------------------------------+-------------+
341 rows in set (0.00 sec)

  • 查看各參數(shù) show variables; show variables like 'max_connect%'
mysql> show variables;  //這些參數(shù)均可以在my.cnf中定義
mysql> show variables like 'max_connect%';   //指定查看某個或某些參數(shù)
+--------------------+-------+
| Variable_name      | Value |
+--------------------+-------+
| max_connect_errors | 100   |
| max_connections    | 151   |
+--------------------+-------+
2 rows in set (0.00 sec)
mysql> show variables like 'slow%';
+---------------------+-----------------------------------+
| Variable_name       | Value                             |
+---------------------+-----------------------------------+
| slow_launch_time    | 2                                 |
| slow_query_log      | OFF                               |
| slow_query_log_file | /data/mysql/minglinux-01-slow.log |
+---------------------+-----------------------------------+
3 rows in set (0.00 sec)

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

mysql> show variables like 'max_connect%';
+--------------------+-------+
| Variable_name      | Value |
+--------------------+-------+
| max_connect_errors | 1000  |
| max_connections    | 151   |
+--------------------+-------+
2 rows in set (0.00 sec)

修改參數(shù)的值在內(nèi)存中生效船庇,重啟失效。在/etc/my.cnf文件中修改則永久有效

  • 查看隊(duì)列 show processlist; show full processlist
mysql> show processlist;
+----+------+-----------+------+---------+------+-------+------------------+
| Id | User | Host      | db   | Command | Time | State | Info             |
+----+------+-----------+------+---------+------+-------+------------------+
| 11 | root | localhost | NULL | Query   |    0 | init  | show processlist |
+----+------+-----------+------+---------+------+-------+------------------+
1 row in set (0.00 sec)
mysql> show full processlist;
+----+------+-----------+------+---------+------+-------+-----------------------+
| Id | User | Host      | db   | Command | Time | State | Info                  |
+----+------+-----------+------+---------+------+-------+-----------------------+
| 11 | root | localhost | NULL | Query   |    0 | init  | show full processlist |
+----+------+-----------+------+---------+------+-------+-----------------------+
1 row in set (0.00 sec)

使用show processlist顯示的最后一列(info)可能不完整侣监,使用show full processlist會顯示完整

  • Mysql歷史命令記錄文件
[root@minglinux-01 ~] ls -a|grep mysql_history
.mysql_history
[root@minglinux-01 ~] cat .mysql_history 
_HiStOrY_V2_
show\040database;
show\040databases;
use\040mysql;
select\040*\040from\040user;
show\040databases;
use\040mysql;
show\040tables;
desc\040user;
show\040create\040table\040user\134G;
select\040user();
select\040database();
use\040mysql
use\040mysql;
select\040database();
create\040database\040db1;
show\040databases;
use\040db1;
create\040table\040t1(`id`\040int(4),\040`name`\040char(40));
show\040tables;
show\040create\040table\040t1\134G;
drop\040table\040t1;
create\040table\040t1(`id`\040int(4),`name`\040char(40))\040ENGINE=InnoDB\040DEFAULT\040CHARSET=utf8;
show\040create\040table\040t1\134G;
select\040version();
show\040status;
show\040variables;
show\040variables\040like\040'max_connect%'
show\040variables\040like\040'max_connect%';
show\040variables\040like\040'slow%';
set\040global\040max_connect_errors=1000;\040
show\040variables\040like\040'max_connect%';
show\040processlist;
show\040full\040processlist;

擴(kuò)展

mysql5.7 root密碼更改 http://www.apelearn.com/bbs/thread-7289-1-1.html
myisam 和innodb引擎對比 http://www.pureweber.com/article/myisam-vs-innodb/
知乎上的答案 https://www.zhihu.com/question/20596402
mysql 配置詳解:https://www.jb51.net/article/48082.htm
mysql調(diào)優(yōu): http://www.aminglinux.com/bbs/thread-5758-1-1.html
同學(xué)分享的親身mysql調(diào)優(yōu)經(jīng)歷: http://www.apelearn.com/bbs/thread-11281-1-1.html

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末鸭轮,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子橄霉,更是在濱河造成了極大的恐慌窃爷,老刑警劉巖邑蒋,帶你破解...
    沈念sama閱讀 219,110評論 6 508
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異按厘,居然都是意外死亡医吊,警方通過查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,443評論 3 395
  • 文/潘曉璐 我一進(jìn)店門逮京,熙熙樓的掌柜王于貴愁眉苦臉地迎上來卿堂,“玉大人,你說我怎么就攤上這事懒棉〔菝瑁” “怎么了?”我有些...
    開封第一講書人閱讀 165,474評論 0 356
  • 文/不壞的土叔 我叫張陵策严,是天一觀的道長穗慕。 經(jīng)常有香客問我,道長妻导,這世上最難降的妖魔是什么逛绵? 我笑而不...
    開封第一講書人閱讀 58,881評論 1 295
  • 正文 為了忘掉前任,我火速辦了婚禮倔韭,結(jié)果婚禮上术浪,老公的妹妹穿的比我還像新娘。我一直安慰自己狐肢,他們只是感情好添吗,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,902評論 6 392
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著份名,像睡著了一般。 火紅的嫁衣襯著肌膚如雪妓美。 梳的紋絲不亂的頭發(fā)上僵腺,一...
    開封第一講書人閱讀 51,698評論 1 305
  • 那天,我揣著相機(jī)與錄音壶栋,去河邊找鬼辰如。 笑死,一個胖子當(dāng)著我的面吹牛贵试,可吹牛的內(nèi)容都是我干的琉兜。 我是一名探鬼主播,決...
    沈念sama閱讀 40,418評論 3 419
  • 文/蒼蘭香墨 我猛地睜開眼毙玻,長吁一口氣:“原來是場噩夢啊……” “哼豌蟋!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起桑滩,我...
    開封第一講書人閱讀 39,332評論 0 276
  • 序言:老撾萬榮一對情侶失蹤梧疲,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體幌氮,經(jīng)...
    沈念sama閱讀 45,796評論 1 316
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡缭受,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,968評論 3 337
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了该互。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片米者。...
    茶點(diǎn)故事閱讀 40,110評論 1 351
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖宇智,靈堂內(nèi)的尸體忽然破棺而出蔓搞,到底是詐尸還是另有隱情,我是刑警寧澤普筹,帶...
    沈念sama閱讀 35,792評論 5 346
  • 正文 年R本政府宣布败明,位于F島的核電站,受9級特大地震影響太防,放射性物質(zhì)發(fā)生泄漏妻顶。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,455評論 3 331
  • 文/蒙蒙 一蜒车、第九天 我趴在偏房一處隱蔽的房頂上張望讳嘱。 院中可真熱鬧,春花似錦酿愧、人聲如沸沥潭。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,003評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽钝鸽。三九已至,卻和暖如春庞钢,著一層夾襖步出監(jiān)牢的瞬間拔恰,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 33,130評論 1 272
  • 我被黑心中介騙來泰國打工基括, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留颜懊,地道東北人。 一個月前我還...
    沈念sama閱讀 48,348評論 3 373
  • 正文 我出身青樓风皿,卻偏偏與公主長得像河爹,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子桐款,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 45,047評論 2 355

推薦閱讀更多精彩內(nèi)容