CentOS 9与CentOS8的区别
设置开机自启和以前的版本有点区别
一、安装包准备
MySQL下载地址:/downloads/file/?id=480751
1.将安装上传到/opt/software/
[appview@salve1 software]$ ll 总用量 384624 -rw-rw-r-- 1 appview appview 393852364 5月 6 22:21 mysql-8.0.13-linux-glibc2.12-x86_64.
2.卸载自带的Mysql-libs
rpm -qa | grep -i -E mysql\|mariadb | xargs -n1 sudo rpm -e --nodeps
3.解压到指定目录
[root@salve1 software]# tar -xvf mysql-8.0.13-linux-glibc2.12-x86_64. -C /usr/local/ [root@salve1 software]# cd /usr/local/ [root@salve1 local]# ll 总用量 0 drwxr-xr-x. 2 root root 6 5月 11 2019 bin drwxr-xr-x. 2 root root 6 5月 11 2019 etc drwxr-xr-x. 2 root root 6 5月 11 2019 games drwxr-xr-x. 2 root root 6 5月 11 2019 include drwxr-xr-x. 2 root root 6 5月 11 2019 lib drwxr-xr-x. 2 root root 6 5月 11 2019 lib64 drwxr-xr-x. 2 root root 6 5月 11 2019 libexec drwxr-xr-x 9 root root 172 5月 6 22:36 mysql-8.0.13-linux-glibc2.12-x86_64 drwxr-xr-x. 2 root root 6 5月 11 2019 sbin drwxr-xr-x. 5 root root 49 3月 24 01:32 share drwxr-xr-x. 2 root root 6 5月 11 2019 src [root@salve1 local]# [root@salve1 local]# mv mysql-8.0.13-linux-glibc2.12-x86_64 mysql-8.0.13 [root@salve1 local]# cd mysql-8.0.13/ [root@salve1 mysql-8.0.13]# ll 总用量 448 drwxr-xr-x 2 root root 4096 5月 6 22:36 bin drwxr-xr-x 2 root root 86 5月 6 22:36 docs drwxr-xr-x 3 root root 266 5月 6 22:35 include drwxr-xr-x 6 root root 4096 5月 6 22:36 lib -rw-r--r-- 1 7161 31415 335809 10月 7 2018 LICENSE -rw-r--r-- 1 7161 31415 101807 10月 7 2018 drwxr-xr-x 4 root root 30 5月 6 22:35 man -rw-r--r-- 1 7161 31415 687 10月 7 2018 README -rw-r--r-- 1 7161 31415 700 10月 7 2018 drwxr-xr-x 28 root root 4096 5月 6 22:36 share drwxr-xr-x 2 root root 90 5月 6 22:36 support-files [root@salve1 mysql-8.0.13]# [root@salve1 mysql-8.0.13]# [root@salve1 mysql-8.0.13]# mkdir data [root@salve1 mysql-8.0.13]#
4.创建用户组以及用户密码、改变目录属组
[root@salve1 mysql-8.0.13]# groupadd mysql [root@salve1 mysql-8.0.13]# useradd -g mysql mysql [root@salve1 mysql-8.0.13]# [root@salve1 mysql-8.0.13]# pwd /usr/local/mysql-8.0.13 [root@salve1 mysql-8.0.13]# chown -R mysql:mysql /usr/local/mysql-8.0.13 [root@salve1 mysql-8.0.13]#
5.初始化信息,产生初始密码,把记者等会用得到
[root@salve1 mysql-8.0.13]# cd bin/ [root@salve1 bin]# ./mysqld --user=mysql --basedir=/usr/local/mysql-8.0.13 --datadir=/usr/local/mysql-8.0.13/data/ --initialize 2024-05-06T14:50:12.080585Z 0 [System] [MY-013169] [Server] /usr/local/mysql-8.0.13/bin/mysqld (mysqld 8.0.13) initializing of server in progress as process 33055 2024-05-06T14:50:16.464122Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: (>Rhe5opF*fh ####(初始密码(>Rhe5opF*fh) 2024-05-06T14:50:18.814045Z 0 [System] [MY-013170] [Server] /usr/local/mysql-8.0.13/bin/mysqld (mysqld 8.0.13) initializing of server has completed [root@salve1 bin]#
二、cents8及以前的版本与CentOS Stream 9分水岭从这里开始了
1.cents8以及之前的版本的设置这样就可以了,但CentOS Stream 9和这个有点不一样
[root@salve1 mysql-8.0.13]# cp ./support-files/ /etc//mysql [root@salve1 mysql-8.0.13]# vim /etc//mysql ###### 修改为自己路路径 basedir=/usr/local/mysql-8.0.13 datadir=/usr/local/mysql-8.0.13/data [root@salve1 mysql-8.0.13]# chmod +x /etc//mysql [root@salve1 mysql-8.0.13]# chkconfig --add mysql
2.配置
[root@salve1 mysql-8.0.13]# vim /etc/ #### 添加以下内容 [mysqld] basedir=/usr/local/mysql-8.0.13 datadir=/usr/local/mysql-8.0.13/data port = 3306 character-set-server=utf8mb4 # 其他配置项...
3.启动mysqld
[root@salve1 mysql-8.0.13]# service mysql start Starting MySQL... SUCCESS! [root@salve1 mysql-8.0.13]#
5.查看状态
[root@salve1 mysql-8.0.13]# service mysql status SUCCESS! MySQL running (36456) [root@salve1 mysql-8.0.13]#
二、CentOS Stream 9开机自启设置
1.将mysql命令添加到服务
[root@salve1 mysql-8.0.13]# ln -s /usr/local/mysql-8.0.13/bin/mysql /usr/bin [root@salve1 mysql-8.0.13]# [root@salve1 mysql-8.0.13]# ll /usr/bin/mysql lrwxrwxrwx 1 root root 33 5月 6 23:27 /usr/bin/mysql -> /usr/local/mysql-8.0.13/bin/mysql
2.配置MySQL
创建并配置MySQL的配置文件。该文件通常位于
/etc/
目录下。
vim /etc/
[mysqld] basedir=/usr/local/mysql-8.0.13 datadir=/usr/local/mysql-8.0.13/data port = 3306 character-set-server=utf8mb4 # 创建新表时将使用的默认存储引擎 default-storage-engine=INNODB explicit_defaults_for_timestamp=true #区分大小写设置 0:区分大小写,1:不区分大小写 lower_case_table_names=1 #解决mysql连接慢(201906181517) skip-name-resolve
3.在CentOS Stream 9中,可以使用systemctl
命令来管理服务并设置开机自启。
使用systemd服务单元文件:创建一个新的服务单元文件,例如/etc/systemd/system/
。
在该文件中定义MySQL服务的启动命令、停止命令、用户、组等。
vim /etc/systemd/system/
[Unit] Description=MySQL Server After= [Install] WantedBy= [Service] User=mysql Group=mysql ExecStart=/usr/local/mysql-8.0.13/bin/mysqld --defaults-file=/etc/ ExecStop=/usr/local/mysql-8.0.13/bin/mysqladmin --user=root shutdown Restart=on-failure
注意:上述ExecStart
和ExecStop
中的命令和路径需要根据你的实际安装情况进行调整。
4.启用并启动服务
-
使用
systemctl
命令启用服务:systemctl enable mysqld
-
启动服务:
systemctl start mysqld
-
现在,MySQL服务应该已经设置为开机自启了。
5. 测试和验证
-
重启你的CentOS Stream 9系统,然后检查MySQL服务是否自动启动。
-
你可以使用
systemctl status mysqld
命令来查看MySQL服务的状态。[root@hdp001 mysql-8.0.13]# systemctl status mysqld ● - MySQL Server Loaded: loaded (/etc/systemd/system/; enabled; preset: disabled) Active: active (running) since Sat 2024-05-25 17:43:10 CST; 5min ago Main PID: 14940 (mysqld) Tasks: 37 (limit: 22828) Memory: 370.8M CPU: 2.391s CGroup: // └─14940 /usr/local/mysql-8.0.13/bin/mysqld --defaults-file=/etc/
三、登录测试
1.说明:centos8之前启动和现在的CentOS Stream 9,启动都遇到了这个问题,但CentOS Stream 9,安装了yum install libncurses*登录还是报以下这个错误,centos8就可以成功登录了
[root@salve1 mysql-8.0.13]# mysql -uroot -p mysql: error while loading shared libraries: .5: cannot open shared object file: No such file or directory #### 登录报上面这个错,解决办法 [root@salve1 mysql-8.0.13]# yum install libncurses*
Stream 9多出的操作
因为我们yum 已经安装了,但依赖依旧缺失,我们找一下有没有相应的依赖,结果找到了但没有报错的.5,这个问题我项目中测试环境安装doris配置mysql客户端的时候,也遇到过,百思不得骑解。。。。。。。
后来通过GPT给解决的,包括CentOS Stream 9开机自启的操作
[root@hdp001 mysql-8.0.13]# find / -name \* 2>/dev/null /var/lib/docker/overlay2/0ff41823ead084037731de6f1c3e30844a9ade2dcaf423229a186141cd3f5932/diff/lib/x86_64-linux-gnu/.5 /var/lib/docker/overlay2/0ff41823ead084037731de6f1c3e30844a9ade2dcaf423229a186141cd3f5932/diff/lib/x86_64-linux-gnu/.5.9 /var/lib/docker/overlay2/6e717c4e3a18e2f0f2fa5715955e0fa2aa92b8e2b03ed4fb1e4db12b9e116f99/diff/lib/x86_64-linux-gnu/.5 /var/lib/docker/overlay2/6e717c4e3a18e2f0f2fa5715955e0fa2aa92b8e2b03ed4fb1e4db12b9e116f99/diff/lib/x86_64-linux-gnu/.5.9 /usr/lib64/.6 /usr/lib64/.6.2
接下来利用软连接使 .5 指向.6.2,然后登录验证就成功了,
ln -s /usr/lib64/.6.2 /usr/lib64/.5
四、登录验证以及修改密码
[root@salve1 mysql-8.0.13]# mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 8 Server version: 8.0.13 Copyright (c) 2000, 2018, 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' 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.03 sec) mysql> use mysql; mysql> select user, host from user; +------------------+-----------+ | user | host | +------------------+-----------+ | | localhost | | | localhost | | | localhost | | root | localhost | +------------------+-----------+ 4 rows in set (0.00 sec) ##### 修改远程连接 mysql> update user set host="%" where user="root"; Query OK, 1 row affected (0.08 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> select user, host from user; +------------------+-----------+ | user | host | +------------------+-----------+ | root | % | | | localhost | | | localhost | | | localhost | +------------------+-----------+ #### 刷新 mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) #### 退出 mysql> quit; Bye [root@salve1 mysql-8.0.13]#