[root@VM-24-3-centos mysql]# systemctl start mysqld
Job for mysqld.service failed because the control process exited with error code. See "systemctl status mysqld.service" and "journalctl -xe"for details.
#提示启动失败则根据日志文件排查错误 cat /var/log/mysqld.log 命令查看日志#根据日志信息发现下图错误信息
[root@VM-24-3-centos mysql]# cat /var/log/mysqld.log|grep localhost2022-12-28T07:47:32.089655Z 6[Note][MY-010454][Server] A temporary password is generated for root@localhost: hAwl))w15>Z1
8、连接数据库
[root@VM-24-3-centos mysql]# mysql -u root
ERROR 1045(28000): Access denied for user 'root'@'localhost'(using password: NO)[root@VM-24-3-centos mysql]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.28
Copyright (c)2000, 2022, 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>#修改数据库用户root密码
mysql> alter user 'root'@'localhost' identified by '283532';
Query OK, 0 rows affected (0.01 sec)#退出数据库使用刚才修改的密码登录[root@VM-24-3-centos mysql]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 8.0.28 MySQL Community Server - GPL
Copyright (c)2000, 2022, 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>show databases;
+--------------------+
| Database |
+--------------------+
| information_schema || mysql || performance_schema || sys |
+--------------------+
4 rows inset(0.01 sec)
mysql>exit
Bye
[root@VM-24-3-centos mysql]#
9、使用navicat for mysql连接数据库
#连接时出现上图错误或者是无法连接到主机,则按如下操作[root@VM-24-3-centos mysql]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 19
Server version: 8.0.28 MySQL Community Server - GPL
Copyright (c)2000, 2022, 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> use mysql;
Database changed
mysql> update user sethost='%' where user ='root';
Query OK, 1 row affected (0.01 sec)
Rows matched: 1 Changed: 1 Warnings: 0#此时如果出现错误则执行则将 localhost 改为 % 再次执行
mysql> alter user 'root'@'localhost' identified with mysql_native_password by '283532';
ERROR 1396(HY000): Operation ALTER USER failed for'root'@'localhost'#
mysql> alter user 'root'@'%' identified with mysql_native_password by '283532';
Query OK, 0 rows affected (0.01 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
mysql>