赞
踩
tar -xvf mysql-8.0.36-1.el9.x86_64.rpm-bundle
解压后目录如下:
1.rpm -ivh mysql-community-common-8.0.36-1.el9.x86_64.rpm
2.rpm -ivh mysql-community-client-plugins-8.0.36-1.el9.x86_64.rpm
3.rpm -ivh mysql-community-libs-8.0.36-1.el9.x86_64.rpm
4.rpm -ivh mysql-community-client-8.0.36-1.el9.x86_64.rpm
5.rpm -ivh mysql-community-icu-data-files-8.0.36-1.el9.x86_64.rpm
6.rpm -ivh mysql-community-server-8.0.36-1.el9.x86_64.rpm
查看已经安装的mysql (rpm -qa | grep mysql
)
mysqld --initialize; // mysql 初始化
cat /var/log/mysqld.log | grep password
)[root@localhost mysql]# cat /var/log/mysqld.log | grep password
2024-01-29T02:54:28.654261Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: KKgQ*e=ra5Ld(密码是 KKgQ*e=ra5Ld)
[root@localhost lib]# mysql -uroot -p"KKgQ*e=ra5Ld" ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) # 使用命令 systemctl status mysqld.service 查看mysql 状态 [root@localhost mysql]# systemctl status mysqld.service × mysqld.service - MySQL Server Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; preset: disabled) Active: failed (Result: exit-code) since Mon 2024-01-29 11:01:36 CST; 38s ago Docs: man:mysqld(8) http://dev.mysql.com/doc/refman/en/using-systemd.html Process: 38439 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS) Process: 38466 ExecStart=/usr/sbin/mysqld $MYSQLD_OPTS (code=exited, status=1/FAILURE) Main PID: 38466 (code=exited, status=1/FAILURE) Status: "Server shutdown complete" Error: 13 (权限不够) CPU: 1.143s 1月 29 11:01:35 localhost.localdomain systemd[1]: Starting MySQL Server... 1月 29 11:01:36 localhost.localdomain systemd[1]: mysqld.service: Main process exited, code=exited, status=1/FAILURE 1月 29 11:01:36 localhost.localdomain systemd[1]: mysqld.service: Failed with result 'exit-code'. 1月 29 11:01:36 localhost.localdomain systemd[1]: Failed to start MySQL Server. 1月 29 11:01:36 localhost.localdomain systemd[1]: mysqld.service: Consumed 1.143s CPU time. # 查看mysql 安装目录权限(默认安装在 /var/lib/mysql) [root@localhost lib]# ll drwxr-x--x. 7 mysql mysql 4096 1月 29 11:01 mysql [root@localhost lib]# chmod -R 777 mysql drwxrwxrwx. 7 mysql mysql 4096 1月 29 11:01 mysql #重新启动mysql [root@localhost lib]# systemctl start mysqld.service #登录 [root@localhost lib]# mysql -uroot -p"KKgQ*e=ra5Ld" #开机自启动mysql [root@localhost lib]# systemctl enable mysqld.service
#修改默认密码
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';
Query OK, 0 rows affected (0.00 sec)
#修改运行远程登录访问
mysql> create user 'han'@'%' identified with mysql_native_password by '123456';
Query OK, 0 rows affected (0.01 sec)
mysql> grant all privileges on *.* to 'han'@'%' with grant option;
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
#查看服务器防火墙状态 [root@localhost ~]# systemctl status firewalld ● firewalld.service - firewalld - dynamic firewall daemon Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; preset: enabled) Active: active (running) since Mon 2024-01-29 10:33:29 CST; 47min ago Docs: man:firewalld(1) Main PID: 878 (firewalld) Tasks: 2 (limit: 10762) Memory: 8.0M CPU: 378ms CGroup: /system.slice/firewalld.service └─878 /usr/bin/python3 -s /usr/sbin/firewalld --nofork --nopid 1月 29 10:33:29 localhost systemd[1]: Starting firewalld - dynamic firewall daemon... 1月 29 10:33:29 localhost systemd[1]: Started firewalld - dynamic firewall daemon. #关闭防火墙(开发版本,生产版本可以使用开放端口的命令) [root@localhost ~]# systemctl stop firewalld [root@localhost ~]# systemctl disable firewalld (永久关闭) #开放端口(防火墙不关闭的状态下) [root@localhost ~]# firewall-cmd --zone=public --permanent --add-port=3306/tcp (添加mysql 端口) success [root@localhost ~]# systemctl restart firewalld (重启防火墙)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。