[root@git bin]# pwd /opt/mysql-5.7.23/mysql-5.7.23-el7-x86_64/bin [root@git bin]# ./mysqld --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql/data --initialize 2018-08-03T08:22:14.766220Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2018-08-03T08:22:14.768375Z 0 [ERROR] Can't find error-message file '/usr/local/mysql/share/errmsg.sys'. Check error-message file location and 'lc-messages-dir' configuration directive. 2018-08-03T08:22:15.280059Z 0 [Warning] InnoDB: New log files created, LSN=45790 2018-08-03T08:22:15.372315Z 0 [Warning] InnoDB: Creating foreign key constraint system tables. 2018-08-03T08:22:15.435202Z 0 [Warning] No existing UUID has been found, so we assume that thisis the first time that this server has been started. Generating a new UUID: 543f3d19-96f6-11e8-a609-525400603f3a. 2018-08-03T08:22:15.486161Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened. 2018-08-03T08:22:15.486770Z 1 [Note] A temporary password is generated for root@localhost: wM<vlfOyU8kN //到这里就安装成功了--这个是密码:"wM<vlfOyU8kN"
2.重新启动mysql服务 [root@git bin]# service mysqld restart Stopping MySQL: [ OK ] Starting MySQL: [ OK ]
3.登录MySQL并修改MySQL的root密码 [root@nginx-test ~]# mysql -uroot -p Enter password: # 不需要输入密码直接接入MySQL Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 14159 Server version: 5.7.27 MySQL Community Server (GPL)
Copyright (c) 2000, 2019, 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'forhelp. Type '\c' to clear the current input statement.
mysql> use mysql; Database changed mysql> UPDATE user SET Password = password ('new-password') WHERE User = 'root'; Query OK, 0 rows affected (0.00 sec) Rows matched: 2 Changed: 0 Warnings: 0 mysql> flush privileges; Query OK, 0 rows affected (0.01 sec) mysql>quit ;
第二种修改密码方法
1 2 3 4
mysql> use mysql; mysql> set password for root@localhost = password('123456'); 如果报错需要先执行 mysql> flush privileges;
7.2 mysql用户远程链接
1 2 3
mysql>use mysql; mysql>update user set host = '%'where user= 'root'; mysql>select host, user from user;
] mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 10 Server version: 8.2.0 MySQL Community Server - GPL
Copyright (c) 2000, 2023, Oracle and/or its affiliates.
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> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'root@123'; mysql> ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'root@123'; mysql> flush privileges;