1、初始化
mysql5.7的初始化与之前不同:
mysqld --initialize --user=mysql
// 之前是
scripts/mysql_install_db --user=mysql
初始化root密码区别:
// 初始化后会给出初始密码
[Note] A temporary password is generated for root@localhost: 2sqrm4P9hk,w
// 之前是自己设置密码:
mysqladmin -u root password '123abc456'
2、mysql启动报错
[root@localhost mysql]# mysqld start
2020-06-15T12:08:55.411294Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2020-06-15T12:08:55.411432Z 0 [Note] --secure-file-priv is set to NULL. Operations related to importing and exporting data are disabled
2020-06-15T12:08:55.411489Z 0 [Note] mysqld (mysqld 5.7.29) starting as process 36340 ...
2020-06-15T12:08:55.415176Z 0 [ERROR] Fatal error: Please read "Security" section of the manual to find out how to run mysqld as root!
2020-06-15T12:08:55.415207Z 0 [ERROR] Aborting
2020-06-15T12:08:55.415243Z 0 [Note] Binlog end
2020-06-15T12:08:55.415453Z 0 [Note] mysqld: Shutdown complete
此处 mysql是出于安全考虑,默认拒绝用root账号启动mysql服务。
解决办法:通过在命令后面加上--user=root 进行强制使用root账号启动
mysqld --user=root
启动后用初始化密码登录
mysql -uroot -p2sqrm4P9hk,w
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 5.7.29
Copyright (c) 2000, 2020, 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> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
提示要先修改密码:
mysql> alter user 'root'@'localhost' identified by '123abc456';
Query OK, 0 rows affected (0.01 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
连接成功