[root@node2 bin]# ./mysqld --initialize --basedir=/usr/local/mysql5.7 --datadir=/data/mysql5.7 --user=mysql
2022-02-28T09:39:22.246862Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see d
ocumentation for more details).2022-02-28T09:39:22.581770Z 0 [Warning] InnoDB: New log files created, LSN=45790
2022-02-28T09:39:22.619303Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2022-02-28T09:39:22.682275Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generatin
g a new UUID: 4f60dbc1-987a-11ec-80c9-000c2966d814.2022-02-28T09:39:22.682885Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2022-02-28T09:39:22.972637Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2022-02-28T09:39:22.972654Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2022-02-28T09:39:22.973270Z 0 [Warning] CA certificate is self signed.
2022-02-28T09:39:23.042745Z 1 [Note] A temporary password is generated for root@localhost: xLdaz8jdqa
初始化完成之后进行登录报错
[root@node2 ~]# mysql -u root -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO) denied for user 'root'@'localhost' (using password: NO)
解决方法一:
按照忘记root密码处理,mysqld_safe
# systemctl stop mysql5.7
# mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
# mysql -u root mysql
mysql> update user set authentication_string=password('新密码') where user='root' and Host='localhost';
mysql> FLUSH PRIVILEGES;
mysql> quit
# systemctl restart mysql5.7
# mysql -uroot -p
Enter password: <输入新设的密码newpassword>
解决方法二:
初始化安全配置,执行mysql_secure_installation,执行该命令之前需要打开服务
systemctl start mysql5.7
[root@node2 bin]# mysql_secure_installation
Securing the MySQL server deployment.
Connecting to MySQL server using password in '/root/.mysql_secret'
Error: Can't connect to local MySQL server through socket '/tmp/' (2)
亲测有效,解决Can 't connect to local MySQL server through socket '/tmp/ '(2) ";
/hjf161105/article/details/78850658
处理完没有/tmp/的问题之后再次执行mysql_secure_installation
[root@node2 bin]# ./mysql_secure_installation
Securing the MySQL server deployment.
Connecting to MySQL server using password in '/root/.mysql_secret'
VALIDATE PASSWORD PLUGIN can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD plugin?
Press y|Y for Yes, any other key for No: y
There are three levels of password validation policy:
LOW Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary file
Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 0
Using existing password for root.
Estimated strength of the password: 100
Change the password for root ? ((Press y|Y for Yes, any other key for No) : y
New password:
Re-enter new password:
Estimated strength of the password: 25
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y
... Failed! Error: Your password does not satisfy the current policy requirements
New password:
Re-enter new password:
Estimated strength of the password: 25
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : n
New password:
Re-enter new password:
Estimated strength of the password: 25
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y
... Failed! Error: Your password does not satisfy the current policy requirements
New password:
Re-enter new password:
Sorry, passwords do not match.
New password:
Re-enter new password:
至此可以登录
[root@node2 ~]# mysql -u root -p
mysql> select user,host from ;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
提示必须修改密码才可以执行其他操作
mysql> ALTER USER USER() IDENTIFIED BY '123456';
如果mysql_secure_installation操作,密码123456提示太简单,修改复杂度即可。
另外一个坑:
--登录的用户没有 with grant option权限
mysql> grant all privileges on *.* to sys@'localhost' identified by '123456';
ERROR 1045 (28000): Access denied for user 'system'@'localhost' (using password: YES)