准备工作:
1.查看系统是否安装mysql
rpm -qa | grep -i mysql
2.如何卸载mysql
rpm -e --nodeps xxxx
3./usr/local/路径下创建mysql的目录
mkdir /usr/local/mysql
4.wget 下载mysql库
wget https://downloads.mysql.com/archives/community/MySQL-5.5.49-.linux2.6.x86_64.rpm-bundle.tar
也可以离线下载mysql库上传到创建的目录下(如何将文件移动到linux系统下,参考文章:CSDN)
解压缩文件
tar -xvf /usr/local/mysql/mysql-5.7.9-1.el5.x86_64.rpm-bundle.tar -C /usr/local/mysql
这里用的MySQL Community 版本:这是MySQL的主要版本,是一个开源的免费版本,适用于开发和生产环境
然后安装 报错
参考文章:rpm安装mysql5.7.9_you are using mysql as an anonymous user and anony-CSDN博客
说是有安装顺序好吧再来一次
卸载掉linux原本有的mariadb库
rpm -e --nodeps mariadb-libs-5.5.68-1.el7.x86_64
还是报错
warning: mysql-community-common-5.7.9-1.el5.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
查询说是yum安装了旧版本的GPG keys造成的 解决办法:
后面加上 --force --nodeps,还是报错但是好像成功了
查看mysql是否启动
[root@localhost ~]# sudo systemctl status mysqld
[root@localhost mysqld]# systemctl status mysqld
● mysqld.service - SYSV: MySQL database server.
Loaded: loaded (/etc/rc.d/init.d/mysqld; bad; vendor preset: disabled)
Active: failed (Result: exit-code) since Fri 2024-02-02 17:00:10 CST; 10min ago
Docs: man:systemd-sysv-generator(8)
Process: 17208 ExecStart=/etc/rc.d/init.d/mysqld start (code=exited, status=1/FAILURE)
Feb 02 17:00:10 localhost.localdomain systemd[1]: Starting SYSV: MySQL database server....
Feb 02 17:00:10 localhost.localdomain mysqld[17208]: Initializing MySQL database: 2024-02-02T09:00:10.752302Z 0 [Warning] TI...ils).
Feb 02 17:00:10 localhost.localdomain mysqld[17208]: 2024-02-02T09:00:10.758763Z 0 [ERROR] --initialize specified but the dat...ting.
Feb 02 17:00:10 localhost.localdomain mysqld[17208]: 2024-02-02T09:00:10.758882Z 0 [ERROR] Aborting
Feb 02 17:00:10 localhost.localdomain mysqld[17208]: [FAILED]
Feb 02 17:00:10 localhost.localdomain systemd[1]: mysqld.service: control process exited, code=exited status=1
Feb 02 17:00:10 localhost.localdomain systemd[1]: Failed to start SYSV: MySQL database server..
Feb 02 17:00:10 localhost.localdomain systemd[1]: Unit mysqld.service entered failed state.
Feb 02 17:00:10 localhost.localdomain systemd[1]: mysqld.service failed.
Hint: Some lines were ellipsized, use -l to show in full.
[root@localhost mysqld]# ps -ef | grep mysql(查看当前有这个进程)
root 17318 1643 0 17:12 pts/0 00:00:00 grep --color=auto mysql
[root@localhost mysqld]# kill 1643(kill掉进程再启动)
[root@localhost mysqld]# 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.
[root@localhost mysqld]# journalctl -xe(查看日志)
Feb 02 17:09:59 localhost.localdomain postfix/master[14996]: warning: process /usr/libexec/postfix/pickup pid 17309 exit status 127
Feb 02 17:09:59 localhost.localdomain postfix/master[14996]: warning: /usr/libexec/postfix/pickup: bad command startup -- throttling
Feb 02 17:10:59 localhost.localdomain postfix/master[14996]: warning: process /usr/libexec/postfix/pickup pid 17314 exit status 127
Feb 02 17:10:59 localhost.localdomain postfix/master[14996]: warning: /usr/libexec/postfix/pickup: bad command startup -- throttling
Feb 02 17:11:59 localhost.localdomain postfix/master[14996]: warning: process /usr/libexec/postfix/pickup pid 17316 exit status 127
Feb 02 17:11:59 localhost.localdomain postfix/master[14996]: warning: /usr/libexec/postfix/pickup: bad command startup -- throttling
Feb 02 17:12:59 localhost.localdomain postfix/master[14996]: warning: process /usr/libexec/postfix/pickup pid 17324 exit status 127
Feb 02 17:12:59 localhost.localdomain postfix/master[14996]: warning: /usr/libexec/postfix/pickup: bad command startup -- throttling
Feb 02 17:13:59 localhost.localdomain postfix/master[14996]: warning: process /usr/libexec/postfix/pickup pid 17325 exit status 127
Feb 02 17:13:59 localhost.localdomain postfix/master[14996]: warning: /usr/libexec/postfix/pickup: bad command startup -- throttling
Feb 02 17:14:59 localhost.localdomain postfix/master[14996]: warning: process /usr/libexec/postfix/pickup pid 17326 exit status 127
Feb 02 17:14:59 localhost.localdomain postfix/master[14996]: warning: /usr/libexec/postfix/pickup: bad command startup -- throttling
Feb 02 17:15:28 localhost.localdomain polkitd[15165]: Registered Authentication Agent for unix-process:17327:1875666611 (system bus n
Feb 02 17:15:28 localhost.localdomain systemd[1]: Starting SYSV: MySQL database server....
-- Subject: Unit mysqld.service has begun start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit mysqld.service has begun starting up.
Feb 02 17:15:28 localhost.localdomain mysqld[17333]: Initializing MySQL database: 2024-02-02T09:15:28.764573Z 0 [Warning] TIMESTAMP
Feb 02 17:15:28 localhost.localdomain mysqld[17333]: 2024-02-02T09:15:28.770303Z 0 [ERROR] --initialize specified but the data direct
Feb 02 17:15:28 localhost.localdomain mysqld[17333]: 2024-02-02T09:15:28.770412Z 0 [ERROR] Aborting
Feb 02 17:15:28 localhost.localdomain mysqld[17333]: [FAILED]
Feb 02 17:15:28 localhost.localdomain systemd[1]: mysqld.service: control process exited, code=exited status=1
Feb 02 17:15:28 localhost.localdomain systemd[1]: Failed to start SYSV: MySQL database server..
-- Subject: Unit mysqld.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit mysqld.service has failed.
--
-- The result is failed.
Feb 02 17:15:28 localhost.localdomain systemd[1]: Unit mysqld.service entered failed state.
Feb 02 17:15:28 localhost.localdomain systemd[1]: mysqld.service failed.
Feb 02 17:15:28 localhost.localdomain polkitd[15165]: Unregistered Authentication Agent for unix-process:17327:1875666611 (system bus
[root@localhost mysqld]# cat /etc/my.cnf(查看配置文件)
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
[root@localhost mysqld]# vi /etc/my.cnf(修改配置文件)
datadir=/var/lib/mysql/data
[root@localhost mysqld]# cd /var/lib/mysql
[root@localhost mysql]# ls
ca-key.pem ca.pem client-cert.pem client-key.pem private_key.pem public_key.pem server-cert.pem server-key.pem
[root@localhost mysql]# mkdir data(创建一个data目录)
[root@localhost mysql]# ls -l
total 32
-rw-------. 1 mysql mysql 1675 Feb 2 16:31 ca-key.pem
-rw-r--r--. 1 mysql mysql 1070 Feb 2 16:31 ca.pem
-rw-r--r--. 1 mysql mysql 1078 Feb 2 16:31 client-cert.pem
-rw-------. 1 mysql mysql 1679 Feb 2 16:31 client-key.pem
drwxr-xr-x. 2 root root 6 Feb 2 17:27 data
-rw-------. 1 mysql mysql 1679 Feb 2 16:31 private_key.pem
-rw-r--r--. 1 mysql mysql 451 Feb 2 16:31 public_key.pem
-rw-r--r--. 1 mysql mysql 1078 Feb 2 16:31 server-cert.pem
-rw-------. 1 mysql mysql 1679 Feb 2 16:31 server-key.pem
[root@localhost mysql]# systemctl start mysqld(再次启动正常)
[root@localhost mysql]# systemctl status mysqld
● mysqld.service - SYSV: MySQL database server.
Loaded: loaded (/etc/rc.d/init.d/mysqld; bad; vendor preset: disabled)
Active: active (running) since Fri 2024-02-02 17:28:10 CST; 9s ago
Docs: man:systemd-sysv-generator(8)
Process: 17401 ExecStart=/etc/rc.d/init.d/mysqld start (code=exited, status=0/SUCCESS)
Main PID: 17686 (mysqld)
CGroup: /system.slice/mysqld.service
├─17490 /bin/sh /usr/bin/mysqld_safe --datadir=/var/lib/mysql/data --socket=/var/lib/mysql/mysql.sock --pid-file=/var/r...
└─17686 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql/data --plugin-dir=/usr/lib64/mysql/plugin --user=mysql...
Feb 02 17:28:03 localhost.localdomain systemd[1]: Starting SYSV: MySQL database server....
Feb 02 17:28:07 localhost.localdomain mysqld[17401]: Initializing MySQL database: [ OK ]
Feb 02 17:28:10 localhost.localdomain mysqld[17401]: Starting mysqld: [ OK ]
Feb 02 17:28:10 localhost.localdomain systemd[1]: mysqld.service: Supervising process 17686 which is not our child. We'll mo...exits.
Feb 02 17:28:10 localhost.localdomain systemd[1]: Started SYSV: MySQL database server..
Hint: Some lines were ellipsized, use -l to show in full.
查看mysql临时root密码
[root@localhost mysql]# sudo grep 'temporary password' /var/log/mysqld.log
登录进去:
[root@localhost mysql]# mysql -u root -p
重置密码
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'XXXXXXX(这是新密码)';
Query OK, 0 rows affected (0.00 sec)