3 安装组件
需要安装的组件:common、libs、client、server。[root@daniu101 mysql]# rpm -ivh mysql-community-common-8.0.24-1.el8.x86_64.rpm --nodeps --force[root@daniu101 mysql]# rpm -ivh mysql-community-libs-8.0.24-1.el8.x86_64.rpm --nodeps --force[root@daniu101 mysql]# rpm -ivh mysql-community-client-8.0.24-1.el8.x86_64.rpm --nodeps --force[root@daniu101 mysql]# rpm -ivh mysql-community-server-8.0.24-1.el8.x86_64.rpm --nodeps --force[root@daniu101 mysql]# rpm -qa | grep mysqlmysql-community-server-8.0.24-1.el8.x86_64mysql-community-common-8.0.24-1.el8.x86_64mysql-community-libs-8.0.24-1.el8.x86_64mysql-community-client-8.0.24-1.el8.x86_64 4 初始化配置
[root@daniu101 mysql]# mysqld --initialize;[root@daniu101 mysql]# chown mysql:mysql /var/lib/mysql -R;[root@daniu101 mysql]# systemctl start mysqld.service;[root@daniu101 mysql]# systemctl enable mysqld; 5 重置密码、查看端口
[root@daniu101 mysql]# cat /var/log/mysqld.log | grep password2021-05-04T09:32:12.661237Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: Az.%h(s5gUrl[root@daniu101 mysql]# mysql -uroot -pEnter password:Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 8Server version: 8.0.24Copyright (c) 2000, 2021, Oracle and/or its affiliates.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.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 '123456';Query OK, 0 rows affected (0.00 sec) mysql> use mysql;Reading table information for completion of table and column namesYou can turn off this feature to get a quicker startup with -ADatabase changed mysql> update user set host='%' where user ='root';Query OK, 1 row affected (0.00 sec)Rows matched: 1 Changed: 1 Warnings: 0 mysql> flush privileges;Query OK, 0 rows affected (0.00 sec) mysql> show global variables like 'port';mysql> exit;Bye # 1410 异常时:mysql> GRANT ALL ON *.* TO 'root'@'%';mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';# 2058 异常时mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';# 1396异常时mysql> ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'password'; 6 各种服务状态
# 启动mysql服务[root@daniu101 mysql]# systemctl start mysqld.service# 停止mysql服务[root@daniu101 mysql]# systemctl stop mysqld.service# 重启mysql服务[root@daniu101 mysql]# systemctl restart mysqld.service# 查看mysql服务当前状态[root@daniu101 mysql]# systemctl status mysqld.service# 设置mysql服务开机自启动[root@daniu101 mysql]# systemctl enable mysqld.service# 停止mysql服务开机自启动[root@daniu101 mysql]# systemctl disable mysqld.service 7 远程登录
注意:安全组打开3306端口。