MySql 8.0.11安装配置教程
官网地址:
我这里是rhel6.5的系统,因此选择redhat 6 x86,64bit操作系统---下载第一个rpm bundle即可--mysql-8.0.11-1.el6.x86_64.rpm-bundle.tar。
目前mysql8.0.11社区版提供了多种多样的安装方式,但是并未发现针对linux generic安装包包含的mysql_secure_installation的安装说明。
因此这里使用推荐的rpm安装:
一、mysql-8.0.11-1.el6.x86_64.rpm-bundle.tar解压后有如下7个文件:
-rw-r--r-- 1 root root 28987588 apr 9 01:06 mysql-community-client-8.0.11-1.el6.x86_64.rpm -rw-r--r-- 1 root root 672184 apr 9 01:06 mysql-community-common-8.0.11-1.el6.x86_64.rpm -rw-r--r-- 1 root root 4443296 apr 9 01:06 mysql-community-devel-8.0.11-1.el6.x86_64.rpm -rw-r--r-- 1 root root 2579460 apr 9 01:06 mysql-community-libs-8.0.11-1.el6.x86_64.rpm -rw-r--r-- 1 root root 1902676 apr 9 01:06 mysql-community-libs-compat-8.0.11-1.el6.x86_64.rpm -rw-r--r-- 1 root root 395918848 apr 9 01:07 mysql-community-server-8.0.11-1.el6.x86_64.rpm -rw-r--r-- 1 root root 49092596 apr 9 01:07 mysql-community-test-8.0.11-1.el6.x86_64.rpm
然后创建mysql用户:
useradd mysql passwd mysql
二、安装顺序为:(建议装之前先把之前的mysql相关包全部卸载,rpm -e --nodeps <包名>即可)
[root@python ~]# rpm -ivh mysql-community-common-8.0.11-1.el6.x86_64.rpm warning: mysql-community-common-8.0.11-1.el6.x86_64.rpm: header v3 dsa/sha1 signature, key id 5072e1f5: nokey preparing... ########################################### [100%] 1:mysql-community-common ########################################### [100%] [root@python ~]# rpm -ivh mysql-community-libs-8.0.11-1.el6.x86_64.rpm warning: mysql-community-libs-8.0.11-1.el6.x86_64.rpm: header v3 dsa/sha1 signature, key id 5072e1f5: nokey preparing... ########################################### [100%] 1:mysql-community-libs ########################################### [100%] [root@python ~]# rpm -ivh mysql-community-libs-compat-8.0.11-1.el6.x86_64.rpm warning: mysql-community-libs-compat-8.0.11-1.el6.x86_64.rpm: header v3 dsa/sha1 signature, key id 5072e1f5: nokey preparing... ########################################### [100%] file /usr/lib64/mysql/libmysqlclient.so.16.0.0 from install of mysql-community-libs-compat-8.0.11-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.73-8.0.1.el6_8.x86_64 file /usr/lib64/mysql/libmysqlclient_r.so.16.0.0 from install of mysql-community-libs-compat-8.0.11-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.73-8.0.1.el6_8.x86_64 [root@python ~]# rpm -e --nodeps mysql-libs-5.1.73-8.0.1.el6_8.x86_64 [root@python ~]# rpm -ivh mysql-community-libs-compat-8.0.11-1.el6.x86_64.rpm warning: mysql-community-libs-compat-8.0.11-1.el6.x86_64.rpm: header v3 dsa/sha1 signature, key id 5072e1f5: nokey preparing... ########################################### [100%] 1:mysql-community-libs-co########################################### [100%] [root@python ~]# rpm -ivh mysql-community-server-8.0.11-1.el6.x86_64.rpm warning: mysql-community-server-8.0.11-1.el6.x86_64.rpm: header v3 dsa/sha1 signature, key id 5072e1f5: nokey error: failed dependencies: mysql-community-client(x86-64) >= 8.0.0 is needed by mysql-community-server-8.0.11-1.el6.x86_64 [root@python ~]# rpm -ivh mysql-community-client-8.0.11-1.el6.x86_64.rpm warning: mysql-community-client-8.0.11-1.el6.x86_64.rpm: header v3 dsa/sha1 signature, key id 5072e1f5: nokey preparing... ########################################### [100%] 1:mysql-community-client ########################################### [100%] [root@python ~]# rpm -ivh mysql-community-server-8.0.11-1.el6.x86_64.rpm warning: mysql-community-server-8.0.11-1.el6.x86_64.rpm: header v3 dsa/sha1 signature, key id 5072e1f5: nokey preparing... ########################################### [100%] 1:mysql-community-server ########################################### [100%] [root@python ~]# rpm -ivh mysql-community-devel-8.0.11-1.el6.x86_64.rpm warning: mysql-community-devel-8.0.11-1.el6.x86_64.rpm: header v3 dsa/sha1 signature, key id 5072e1f5: nokey preparing... ########################################### [100%] 1:mysql-community-devel ########################################### [100%] ^[[a[root@python ~]# rpm -ivh mysql-community-test-8.0.11-1.el6.x86_64.rpm warning: mysql-community-test-8.0.11-1.el6.x86_64.rpm: header v3 dsa/sha1 signature, key id 5072e1f5: nokey error: failed dependencies: perl(json) is needed by mysql-community-test-8.0.11-1.el6.x86_64 --懒的去装perl了,因此测试套件就不装了。
三、安装完毕后相关信息如下:
[root@python ~]# mysql -v mysql ver 8.0.11 for linux on x86_64 (mysql community server - gpl) [root@python ~]# ll /etc/init.d/mysqld -rwxr-xr-x 1 root root 7166 apr 8 16:21 /etc/init.d/mysqld [root@python ~]# ll /etc/my.cnf --配置文件位置 -rw-r--r-- 1 root root 1188 apr 8 16:21 /etc/my.cnf
默认的datadir是在/var/lib/mysql/,可以通过修改my.cnf修改,启动命令如下:
[root@python ~]# service mysqld start initializing mysql database: [ ok ] starting mysqld: [ ok ]
四、发现没密码不能登录,于是添加skip-grant-tables到my.cnf,重启进去重置密码
mysql> alter user root@'localhost' identified by 'mysql'; error 1290 (hy000): the mysql server is running with the --skip-grant-tables option so it cannot execute this statement mysql> exit bye
居然不能改。。。于是:
mysql> delete from mysql.user where user='root'; query ok, 1 row affected (0.10 sec) mysql> flush privileges; query ok, 0 rows affected (0.00 sec) mysql> create user root@'localhost' identified by 'mysql'; error 1819 (hy000): your password does not satisfy the current policy requirements
还是不能改,查看密码复杂度要求:
mysql> show variables like '%pass%'; +----------------------------------------------+-----------------+ | variable_name | value | +----------------------------------------------+-----------------+ | caching_sha2_password_auto_generate_rsa_keys | on | | caching_sha2_password_private_key_path | private_key.pem | | caching_sha2_password_public_key_path | public_key.pem | | default_password_lifetime | 0 | | disconnect_on_expired_password | on | | mysql_native_password_proxy_users | off | | password_history | 0 | | password_reuse_interval | 0 | | report_password | | | sha256_password_auto_generate_rsa_keys | on | | sha256_password_private_key_path | private_key.pem | | sha256_password_proxy_users | off | | sha256_password_public_key_path | public_key.pem | | validate_password.check_user_name | on | | validate_password.dictionary_file | | | validate_password.length | 8 | | validate_password.mixed_case_count | 1 | | validate_password.number_count | 1 | | validate_password.policy | medium | | validate_password.special_char_count | 1 | +----------------------------------------------+-----------------+
查看官网
发现此值有3个,如下所示:
于是设置为0,然后将validate_password.length设置为4,表示最少需要4字符。之所以设置为4是因为这个参数的值不能小于如下公式的计算结果:
validate_password.number_count + validate_password.special_char_count + (2 * validate_password.mixed_case_count)
于是继续创建用户,mysql8.0取消了直接grant创建用户的语法,只能先create user再grant,因此创建root如下:
mysql> create user root@'localhost' identified by 'mysql'; error 1396 (hy000): operation create user failed for 'root'@'localhost' mysql> flush privileges; query ok, 0 rows affected (0.00 sec) mysql> create user root@'localhost' identified by 'mysql'; error 1396 (hy000): operation create user failed for 'root'@'localhost'
尼玛...什么玩意儿?
于是去逛了一圈*,都说这是一个bug,于是操作如下:
mysql> drop user root@'localhost'; --是的没错,虽然没有root@'localhost'用户,但你还是要删一遍。 query ok, 0 rows affected (0.05 sec) mysql> flush privileges; query ok, 0 rows affected (0.01 sec) mysql> create user root@'localhost' identified by 'mysql'; query ok, 0 rows affected (0.03 sec) mysql> grant all on *.* to root@'localhost' with grant option; query ok, 0 rows affected (0.03 sec)
终于改完密码了...去掉参数文件的skip-grant-tables参数,service mysqld restart重启服务。
五、终于设置好密码了,建一个测试用户leo,然后尝试远程连接下吧:
$ mysql -uleo -pmysql -h192.168.1.193 mysql: [warning] using a password on the command line interface can be insecure. error 2059 (hy000): authentication plugin 'caching_sha2_password' cannot be loaded: /usr/lib/mysql/plugin/caching_sha2_password.so: cannot open shared object file: no such file or directory
我这5.7的mysql工具都连不上,这就尴尬了,查看认证相关参数:
mysql> show variables like '%auth%'; +-------------------------------+-----------------------+ | variable_name | value | +-------------------------------+-----------------------+ | default_authentication_plugin | caching_sha2_password | +-------------------------------+-----------------------+ 1 row in set (0.02 sec)
查看官网发现此值的取值如下:
官网还说此值影响create user不显式指定auth plugin时密码的默认加密算法,卧槽...那岂不是说我之前创建的leo用户使用的是默认的caching_sha2_password认证,查看一下:
mysql> select user,host,plugin from mysql.user; +------------------+-----------+-----------------------+ | user | host | plugin | +------------------+-----------+-----------------------+ | leo | % | caching_sha2_password | | mysql.infoschema | localhost | mysql_native_password | | mysql.session | localhost | mysql_native_password | | mysql.sys | localhost | mysql_native_password | | root | localhost | caching_sha2_password | +------------------+-----------+-----------------------+
完了,全tm完了......
显然不能直接update plugin,因为这可能导致加密的密码无法被正确解密,你所有的密码都会变异,因此除外全部删掉重建。
首先需要在my.cnf里添加:default_authentication_plugin=mysql_native_password,然后service mysqld restart重启服务:
mysql> drop user leo; query ok, 0 rows affected (0.10 sec) mysql> flush privileges; query ok, 0 rows affected (0.00 sec) mysql> create user leo identified by 'mysql'; query ok, 0 rows affected (0.02 sec) mysql> grant all on *.* to leo; query ok, 0 rows affected (0.08 sec) $mysql -v mysql ver 14.14 distrib 5.7.20, for linux (x86_64) using editline wrapper $ mysql -uleo -pmysql -h192.168.1.193 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 16 server version: 8.0.11 mysql community server - gpl copyright (c) 2000, 2017, 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>
至此远程连接正常。
总结
以上所述是小编给大家介绍的mysql 8.0.11安装配置教程,希望对大家有所帮助
推荐阅读
-
MySQL安装教程
-
JDK1.9怎么安装配置?Java SE 9(JDK9)详细安装教程+环境变量配置方法
-
Android Studio安装配置方法图文教程
-
CentOS7下mysql 8.0.16 安装配置方法图文教程
-
win10下mysql 8.0.16 winx64安装配置方法图文教程
-
mysql 8.0.16 压缩包安装配置方法图文教程
-
Windows10 mysql 8.0.12 非安装版配置启动方法
-
Windows10下mysql 8.0.16 安装配置方法图文教程
-
mysql 8.0.16 winx64.zip安装配置方法图文教程
-
windows下mysql 8.0.16 安装配置方法图文教程