// 启动MySQL
[root@wode006 tools]# systemctl start mysqld
// 以root连接到MySQL
[root@wode006 tools]# mysql -u root
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 5.6.25 MySQL Community Server (GPL)
Copyright (c) 2000, 2015, 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> select user,host,password from mysql.user
-> ;
+------+-----------+----------+
| user | host | password |
+------+-----------+----------+
| root | localhost | |
| root | 127.0.0.1 | |
| root | ::1 | |
| | localhost | |
+------+-----------+----------+
4 rows in set (0.00 sec)
mysql>
// 设置密码
mysql> set password for root@localhost=password(‘your-password‘);
Query OK, 0 rows affected (0.00 sec)
// 查看密码
mysql> select user,host,password from mysql.user;
+------+-----------+-------------------------------------------+
| user | host | password |
+------+-----------+-------------------------------------------+
| root | localhost | *21ACDCFEB260C9C42B0FC5E5DC741C453A48C99D |
| root | 127.0.0.1 | |
| root | ::1 | |
| | localhost | |
+------+-----------+-------------------------------------------+
4 rows in set (0.00 sec)
// 退出MySQL
mysql> exit
Bye
// 重新登录MySQL
[root@wode006 tools]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 5.6.25 MySQL Community Server (GPL)
原文地址:http://huangchao.blog.51cto.com/10446378/1670744