13.1 設置更改root密碼 13.2 連接mysql 13.3 mysql常用命令

13.1 設置更改root密碼

13.1 設置更改root密碼 13.2 連接mysql 13.3 mysql常用命令
[root@martin001 init.d]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
[root@martin001 init.d]# PATH=$PATH:/usr/local/mysql/bin
[root@martin001 init.d]# vim /etc/profile
[root@martin001 init.d]# source /etc/profile
[root@martin001 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)
[root@martin001 init.d]# mysqladmin -uroot password 'martin.1'
Warning: Using a password on the command line interface can be insecure.
[root@martin001 init.d]# mysql -uroot
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
[root@martin001 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密碼:
[root@martin001 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

13.1 設置更改root密碼 13.2 連接mysql 13.3 mysql常用命令
[root@martin001 ~]# 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)
[root@martin001 ~]# 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
[root@martin001 ~]# 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)

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章