Centos 7 安装MySQL8
一.下载软件
地址:https://dev.mysql.com/downloads/mysql/
二.解压
tar -xvf mysql-8.0.27-1.el7.x86_64.rpm-bundle.tar
解压后的文件有
[root@CentOSA mysql]# ll
总用量 1635440
-rw-r--r--. 1 root root 837345280 1月 2 22:50 mysql-8.0.27-1.el7.x86_64.rpm-bundle.tar
-rw-r--r--. 1 7155 31415 55178328 9月 29 15:33 mysql-community-client-8.0.27-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415 5932800 9月 29 15:34 mysql-community-client-plugins-8.0.27-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415 641616 9月 29 15:34 mysql-community-common-8.0.27-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415 7760100 9月 29 15:34 mysql-community-devel-8.0.27-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415 23637616 9月 29 15:34 mysql-community-embedded-compat-8.0.27-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415 4935900 9月 29 15:34 mysql-community-libs-8.0.27-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415 1264256 9月 29 15:34 mysql-community-libs-compat-8.0.27-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415 470252428 9月 29 15:36 mysql-community-server-8.0.27-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415 267724484 9月 29 15:38 mysql-community-test-8.0.27-1.el7.x86_64.rpm
三.安装
先查看一下是否已经安装了,命令:rpm -qa|grep mariadb
[root@CentOSA ~]# rpm -qa|grep mariadb
mariadb-libs-5.5.56-2.el7.x86_64
[root@CentOSA ~]# rpm -e --nodeps mariadb-libs
然后再安装 。先看看我的安装日志,对安装的顺序还是有一定的要求的,如果报错,根据报错信息调整安装包的次序
// 下面是必须安装的
[root@CentOSA mysql]# rpm -ivh mysql-community-common-8.0.27-1.el7.x86_64.rpm //第一个
警告:mysql-community-common-8.0.27-1.el7.x86_64.rpm: 头V3 DSA/SHA256 Signature, 密钥 ID 5072e1f5: NOKEY
准备中... ################################# [100%]
正在升级/安装...
1:mysql-community-common-8.0.27-1.e################################# [100%]
[root@CentOSA mysql]# rpm -ivh mysql-community-libs-8.0.27-1.el7.x86_64.rpm //报错 需要先安装 mysql-community-client-plugins
警告:mysql-community-libs-8.0.27-1.el7.x86_64.rpm: 头V3 DSA/SHA256 Signature, 密钥 ID 5072e1f5: NOKEY
错误:依赖检测失败:
mysql-community-client-plugins = 8.0.27-1.el7 被 mysql-community-libs-8.0.27-1.el7.x86_64 需要
[root@CentOSA mysql]# rpm -ivh mysql-community-client-plugins-8.0.27-1.el7.x86_64.rpm //第二个
警告:mysql-community-client-plugins-8.0.27-1.el7.x86_64.rpm: 头V3 DSA/SHA256 Signature, 密钥 ID 5072e1f5: NOKEY
准备中... ################################# [100%]
正在升级/安装...
1:mysql-community-client-plugins-8.################################# [100%]
[root@CentOSA mysql]# rpm -ivh mysql-community-libs-8.0.27-1.el7.x86_64.rpm //第三个
警告:mysql-community-libs-8.0.27-1.el7.x86_64.rpm: 头V3 DSA/SHA256 Signature, 密钥 ID 5072e1f5: NOKEY
准备中... ################################# [100%]
正在升级/安装...
1:mysql-community-libs-8.0.27-1.el7################################# [100%]
[root@CentOSA mysql]# rpm -ivh mysql-community-client-8.0.27-1.el7.x86_64.rpm //第四个
警告:mysql-community-client-8.0.27-1.el7.x86_64.rpm: 头V3 DSA/SHA256 Signature, 密钥 ID 5072e1f5: NOKEY
准备中... ################################# [100%]
正在升级/安装...
1:mysql-community-client-8.0.27-1.e################################# [100%]
[root@CentOSA mysql]# rpm -ivh mysql-community-server-8.0.27-1.el7.x86_64.rpm //第五个
警告:mysql-community-server-8.0.27-1.el7.x86_64.rpm: 头V3 DSA/SHA256 Signature, 密钥 ID 5072e1f5: NOKEY
准备中... ################################# [100%]
正在升级/安装...
1:mysql-community-server-8.0.27-1.e################################# [100%]
其余几个包可以根据需求自行安装
四.启动
查询状态
[root@CentOSA mysql]# systemctl status mysqld
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: inactive (dead)
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
启动
[root@CentOSA 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.
排错
//查询状态
[root@CentOSA mysql]# systemctl status mysqld.service
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: failed (Result: exit-code) since 日 2022-01-02 23:13:24 CST; 1min 30s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 10303 ExecStart=/usr/sbin/mysqld $MYSQLD_OPTS (code=exited, status=1/FAILURE)
Process: 10278 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
Main PID: 10303 (code=exited, status=1/FAILURE)
Status: "Server startup in progress"
Error: 13 (权限不够)
//查看配置文件 里面的错误日志位置
[root@CentOSA ~]# less /var/log/mysqld.log
2022-01-02T15:13:09.566926Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2022-01-02T15:13:10.315470Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2022-01-02T15:13:11.310375Z 0 [Warning] [MY-013746] [Server] A deprecated TLS version TLSv1 is enabled for channel mysql_main
2022-01-02T15:13:11.310585Z 0 [Warning] [MY-013746] [Server] A deprecated TLS version TLSv1.1 is enabled for channel mysql_main
2022-01-02T15:13:11.351949Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: /?gWV)zT0v*,
2022-01-02T15:13:23.815821Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.27) starting as process 10303
2022-01-02T15:13:23.981996Z 0 [Warning] [MY-010075] [Server] No existing UUID has been found, so we assume that this is the first time th
at this server has been started. Generating a new UUID: 8760b352-6bde-11ec-b55e-000c2957646d.mysqld: File '/var/lib/mysql/auto.cnf' not found (OS errno 13 - Permission denied) //关键信息
2022-01-02T15:13:23.984477Z 0 [ERROR] [MY-010183] [Server] Failed to create file(file: '/var/lib/mysql/auto.cnf', errno 13)
2022-01-02T15:13:23.984491Z 0 [ERROR] [MY-010076] [Server] Initialization of the server's UUID failed because it could not be read from t
he auto.cnf file. If this is a new server, the initialization failed because it was not possible to generate a new UUID.2022-01-02T15:13:23.984652Z 0 [ERROR] [MY-010119] [Server] Aborting
2022-01-02T15:13:23.985952Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.27) MySQL Community Server -
GPL.2022-01-02T15:22:33.438002Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.27) starting as process 10401
2022-01-02T15:22:33.614273Z 0 [Warning] [MY-000054] [Server] World-writable config file '/var/lib/mysql/auto.cnf' is ignored.
2022-01-02T15:22:33.614701Z 0 [Warning] [MY-010107] [Server] World-writable config file '/var/lib/mysql/auto.cnf' has been removed.
2022-01-02T15:22:33.626367Z 0 [Warning] [MY-010075] [Server] No existing UUID has been found, so we assume that this is the first time th
at this server has been started. Generating a new UUID: cefdc6e3-6bdf-11ec-b9b9-000c2957646d.2022-01-02T15:22:33.683083Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2022-01-02T15:22:34.462945Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2022-01-02T15:22:35.047838Z 0 [Warning] [MY-013746] [Server] A deprecated TLS version TLSv1 is enabled for channel mysql_main
2022-01-02T15:22:35.047947Z 0 [Warning] [MY-013746] [Server] A deprecated TLS version TLSv1.1 is enabled for channel mysql_main
2022-01-02T15:22:35.051540Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2022-01-02T15:22:35.051664Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now s
upported for this channel.2022-01-02T15:22:35.090664Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.27' socket: '/var/lib
/mysql/mysql.sock' port: 3306 MySQL Community Server - GPL.2022-01-02T15:22:35.091684Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060, socket: /var/
run/mysqld/mysqlx.sock/var/log/mysqld.log (END)
//直接找到这个文件夹 授权即可
[root@CentOSA ~]# cd /var/lib/mysql
[root@CentOSA mysql]# ls
auto.cnf ca.pem #ib_16384_0.dblwr ibdata1 #innodb_temp performance_schema server-cert.pem undo_001
binlog.index client-cert.pem #ib_16384_1.dblwr ib_logfile0 mysql private_key.pem server-key.pem undo_002
ca-key.pem client-key.pem ib_buffer_pool ib_logfile1 mysql.ibd public_key.pem sys
//粗暴授权 当然可以根据要求来授权
[root@CentOSA mysql]# chmod -R 777 auto.cnf
启动
[root@CentOSA mysql]# systemctl start mysqld
[root@CentOSA mysql]# systemctl status mysqld.service
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since 日 2022-01-02 23:22:35 CST; 4s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 10377 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
Main PID: 10401 (mysqld)
Status: "Server is operational"
CGroup: /system.slice/mysqld.service
└─10401 /usr/sbin/mysqld
1月 02 23:22:32 CentOSA systemd[1]: Starting MySQL Server...
1月 02 23:22:35 CentOSA systemd[1]: Started MySQL Server.
安装成功!!
进入mysql
[root@CentOSA ~]# mysql -u root //进不去
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
//修改配置文件 最后添加 skip-grant-tables
vi /etc/my.cnf
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
skip-grant-tables
//重启 可以
[root@CentOSA my.cnf.d]# systemctl stop mysqld
[root@CentOSA my.cnf.d]# systemctl start mysqld
//进入
[root@CentOSA my.cnf.d]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 8.0.27 MySQL Community Server - GPL
Copyright (c) 2000, 2021, 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>
修改密码
mysql> use mysql;
mysql> update user set authentication_string='' where user='root'; ## 将密码设置为空(必须在mysql库设置)
mysql> exit
[root@xiaoyaoji ~]# vi /etc/my.cnf ##删除skip那一行
[root@xiaoyaoji ~]# systemctl restart mysqld // 重启服务
[root@xiaoyaoji ~]# mysql -uroot -p
Enter password: ##直接回车
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'root'; ##设置密码
mysql> exit
授权
[root@xiaoyaoji ~]# mysql -uroot -proot
在mysql8.0中 授权语句已经更换,使用之前的sql语句授权会报错;
mysql> create user 'root'@'%' identified by 'Root@123'; ##创建可以所有用户都可以访问的用户规则
mysql> grant all privileges on *.* to 'root'@'%'; ##对这个用户规则进行授权
mysql> flush privileges; ##刷新权限
mysql> exit
使用工具就可以连接了