MySQL8.0安装
Posted 夜间独行的浪子
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了MySQL8.0安装相关的知识,希望对你有一定的参考价值。
mysql 8.0安装
MySQL8从官网下载的压缩包都是tar.xz格式的,
1:先解压这个压缩包
[root@vmtest src]# xz -d mysql-8.0.18-linux-glibc2.12-x86_64.tar.xz [root@vmtest src]# ls mysql-8.0.18-linux-glibc2.12-x86_64.tar -lh -rw-r--r--. 1 7155 31415 2.6G Sep 22 22:33 mysql-8.0.18-linux-glibc2.12-x86_64.tar [root@vmtest src]# tar xvf mysql-8.0.18-linux-glibc2.12-x86_64.tar -C /usr/local/
2:创建软连接,创建数据目录和日志目录
[root@vmtest src]# cd /usr/local/ [root@vmtest local]# ln -s mysql-8.0.18-linux-glibc2.12-x86_64 mysql [root@vmtest local]# ll mysql lrwxrwxrwx. 1 root root 35 Dec 17 18:06 mysql -> mysql-8.0.18-linux-glibc2.12-x86_64 [root@vmtest local]# mkdir -p /data/mysql
3:创建mysql用户,mysql组
shell> groupadd mysql shell> useradd -r -g mysql -s /bin/false mysql
3:初始化数据库
如果有配置文件,在初始化之前加入,初始化之后加入,启动的时候总报错如下内容:【这里应该是某个参数设置问题】
[root@vmtest tmp]# service mysqld start Starting MySQL. ERROR! The server quit without updating PID file (/data/mysql/vmtest.pid). # 日志里面就三行 mysqld: File ‘/data/mysq/mysql-bin.index‘ not found (OS errno 2 - No such file or directory) 2019-12-17T10:56:39.876760Z 0 [System] [MY-010116] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.18) starting as process 5782 2019-12-17T10:56:39.883691Z 0 [ERROR] [MY-010119] [Server] Aborting 2019-12-17T10:56:39.883960Z 0 [System] [MY-010910] [Server] /usr/local/mysql/bin/mysqld: Shutdown complete (mysqld 8.0.18) MySQL Community Server - GPL.
先写配置文件,然后再初始化:其简易配置如下
[mysqld] port=3306 datadir=/data/mysql basedir=/usr/local/mysql default_authentication_plugin=mysql_native_password server_id=3 binlog_format=ROW socket=/data/mysql/mysql.sock [mysqld_safe] pid-file=/data/mysql/vmtest.pid log-error=/data/mysql/vmtest.err
[root@vmtest ~]# cd /usr/local/mysql [root@vmtest mysql]# ./bin/mysqld --datadir=/data/mysql/ --user=mysql --initialize 2019-12-17T10:11:25.378824Z 0 [System] [MY-013169] [Server] /usr/local/mysql-8.0.18-linux-glibc2.12-x86_64/bin/mysqld (mysqld 8.0.18) initializing of server in progress as process 1028 2019-12-17T10:11:40.271309Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: eJfRVq+em9.& [root@vmtest mysql]#
上面依然有临时密码这个说法,
4:启动数据库,
更改数据目录的属主和属组,然后拷贝启动脚本。
[root@vmtest mysql]# chown -R mysql:mysql /data/mysql [root@vmtest mysql]# pwd /usr/local/mysql [root@vmtest mysql]# cp support-files/mysql.server /etc/init.d/mysqld
更改mysqld配置文件中basedir和datadir的位置,
basedir=/usr/local/mysql/
datadir=/data/mysql/
启动mysql服务【下面警告应该是在centos7上应该使用systemctl启动,但是因为习惯这里还是使用了service】
[root@vmtest mysql]# service mysqld start Warning: mysqld.service changed on disk. Run ‘systemctl daemon-reload‘ to reload units. Starting MySQL.Logging to ‘/data/mysql/vmtest.err‘. .. SUCCESS!
连接mysql服务:【这里和MySQL 5.7一样,仍然需要更改密码】
[root@vmtest mysql]# mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or g. Your MySQL connection id is 9 Server version: 8.0.18 Copyright (c) 2000, 2019, 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> show databases; ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement. mysql> alter user ‘root‘@‘localhost‘ identified by ‘1234qwer!@#$‘; Query OK, 0 rows affected (0.06 sec)
整体的安装步骤和MySQL5.7一样,下面说明第一个MySQL5.7不一样的地方。
MySQL的验证插件
mysql的用户验证都是通过插件的方式的,之前的版本中使用的是mysql_native_password插件,但是在MySQL8.0中使用的是caching_sha2_password,这样在MySQL8中创建的用户,在使用旧版本的客户端连接是会有问题的,实例如下:
创建一个账号:【说明,在MySQL8之前,我们可以使用grant语句把创建账号和授权合并成一条语句,但是MySQL8中必须分为如下的两条语句】
mysql> create user ‘dba‘@‘%‘ identified by ‘123456‘; Query OK, 0 rows affected (0.06 sec) mysql> grant all privileges on *.* to ‘dba‘@‘%‘; Query OK, 0 rows affected (0.05 sec)
本地连接一切正常:
[root@vmtest mysql]# mysql --version mysql Ver 8.0.18 for linux-glibc2.12 on x86_64 (MySQL Community Server - GPL) [root@vmtest mysql]# mysql -udba -p123456 mysql: [Warning] Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or g. Your MySQL connection id is 14 Server version: 8.0.18 MySQL Community Server - GPL Copyright (c) 2000, 2019, 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>
但是远程连接就报错了:
[ops@vm42 ~]$ mysql --version mysql Ver 14.14 Distrib 5.6.34, for Linux (x86_64) using EditLine wrapper [ops@vm42 ~]$ mysql -udba -p -h 10.9.68.201 Enter password: ERROR 2059 (HY000): Authentication plugin ‘caching_sha2_password‘ cannot be loaded: /usr/local/mysql/lib/plugin/caching_sha2_password.so: cannot open shared object file: No such file or directory [ops@vm42 ~]
解决办法,更改MySQL8的默认插件,使其仍为mysql_native_password.
mysql> show variables like ‘default_authentication_plugin‘; 【更改这个参数需要重启数据库】 +-------------------------------+-----------------------+ | Variable_name | Value | +-------------------------------+-----------------------+ | default_authentication_plugin | caching_sha2_password | +-------------------------------+-----------------------+ 1 row in set (0.01 sec) mysql> set global default_authentication_plugin=‘mysql_native_password‘; ERROR 1238 (HY000): Variable ‘default_authentication_plugin‘ is a read only variable
在配置文件中配置如下参数:
default_authentication_plugin=mysql_native_password
【说明:对于之前已经创建的用户,其验证仍然使用的是caching_sha2_password】
alter user ‘dba‘@‘%‘ identified with mysql_native_password by ‘123456‘; #更改之前已经验证用户的插件
以上是关于MySQL8.0安装的主要内容,如果未能解决你的问题,请参考以下文章