• 售前

  • 售后

热门帖子
入门百科

MySql 8.0.11安装设置教程

[复制链接]
123457010 显示全部楼层 发表于 2021-10-26 12:23:25 |阅读模式 打印 上一主题 下一主题
官网地点:https://dev.mysql.com/downloads/mysql/
我这里是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个文件:
  1. -rw-r--r-- 1 root root 28987588 Apr 9 01:06 mysql-community-client-8.0.11-1.el6.x86_64.rpm
  2. -rw-r--r-- 1 root root  672184 Apr 9 01:06 mysql-community-common-8.0.11-1.el6.x86_64.rpm
  3. -rw-r--r-- 1 root root  4443296 Apr 9 01:06 mysql-community-devel-8.0.11-1.el6.x86_64.rpm
  4. -rw-r--r-- 1 root root  2579460 Apr 9 01:06 mysql-community-libs-8.0.11-1.el6.x86_64.rpm
  5. -rw-r--r-- 1 root root  1902676 Apr 9 01:06 mysql-community-libs-compat-8.0.11-1.el6.x86_64.rpm
  6. -rw-r--r-- 1 root root 395918848 Apr 9 01:07 mysql-community-server-8.0.11-1.el6.x86_64.rpm
  7. -rw-r--r-- 1 root root 49092596 Apr 9 01:07 mysql-community-test-8.0.11-1.el6.x86_64.rpm
复制代码
然后创建mysql用户:
  1. useradd mysql
  2. passwd mysql
复制代码
二、安装顺序为:(发起装之前先把之前的mysql相关包全部卸载,rpm -e --nodeps <包名>即可)
  1. [root@python ~]# rpm -ivh mysql-community-common-8.0.11-1.el6.x86_64.rpm
  2. warning: mysql-community-common-8.0.11-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
  3. Preparing...        ########################################### [100%]
  4.   1:mysql-community-common ########################################### [100%]
  5. [root@python ~]# rpm -ivh mysql-community-libs-8.0.11-1.el6.x86_64.rpm
  6. warning: mysql-community-libs-8.0.11-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
  7. Preparing...        ########################################### [100%]
  8.   1:mysql-community-libs  ########################################### [100%]
  9. [root@python ~]# rpm -ivh mysql-community-libs-compat-8.0.11-1.el6.x86_64.rpm
  10. warning: mysql-community-libs-compat-8.0.11-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
  11. Preparing...        ########################################### [100%]
  12.   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
  13.   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
  14. [root@python ~]# rpm -e --nodeps mysql-libs-5.1.73-8.0.1.el6_8.x86_64
  15. [root@python ~]# rpm -ivh mysql-community-libs-compat-8.0.11-1.el6.x86_64.rpm
  16. warning: mysql-community-libs-compat-8.0.11-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
  17. Preparing...        ########################################### [100%]
  18.   1:mysql-community-libs-co########################################### [100%]
  19. [root@python ~]# rpm -ivh mysql-community-server-8.0.11-1.el6.x86_64.rpm
  20. warning: mysql-community-server-8.0.11-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
  21. error: Failed dependencies:
  22.   mysql-community-client(x86-64) >= 8.0.0 is needed by mysql-community-server-8.0.11-1.el6.x86_64
  23. [root@python ~]# rpm -ivh mysql-community-client-8.0.11-1.el6.x86_64.rpm
  24. warning: mysql-community-client-8.0.11-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
  25. Preparing...        ########################################### [100%]
  26.   1:mysql-community-client ########################################### [100%]
  27. [root@python ~]# rpm -ivh mysql-community-server-8.0.11-1.el6.x86_64.rpm
  28. warning: mysql-community-server-8.0.11-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
  29. Preparing...        ########################################### [100%]
  30.   1:mysql-community-server ########################################### [100%]
  31. [root@python ~]# rpm -ivh mysql-community-devel-8.0.11-1.el6.x86_64.rpm
  32. warning: mysql-community-devel-8.0.11-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
  33. Preparing...        ########################################### [100%]
  34.   1:mysql-community-devel ########################################### [100%]
  35. ^[[A[root@python ~]# rpm -ivh mysql-community-test-8.0.11-1.el6.x86_64.rpm
  36. warning: mysql-community-test-8.0.11-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
  37. error: Failed dependencies:
  38.   perl(JSON) is needed by mysql-community-test-8.0.11-1.el6.x86_64
  39. --懒的去装perl了,因此测试套件就不装了。
复制代码
三、安装完毕后相关信息如下:
  1. [root@python ~]# mysql -V
  2. mysql Ver 8.0.11 for Linux on x86_64 (MySQL Community Server - GPL)
  3. [root@python ~]# ll /etc/init.d/mysqld
  4. -rwxr-xr-x 1 root root 7166 Apr 8 16:21 /etc/init.d/mysqld
  5. [root@python ~]# ll /etc/my.cnf --配置文件位置
  6. -rw-r--r-- 1 root root 1188 Apr 8 16:21 /etc/my.cnf
复制代码
默认的datadir是在/var/lib/mysql/,可以通过修改my.cnf修改,启动下令如下:
  1. [root@python ~]# service mysqld start
  2. Initializing MySQL database:                [ OK ]
  3. Starting mysqld:  
  4. [ OK ]
复制代码
四、发现没暗码不能登录,于是添加skip-grant-tables到my.cnf,重启进去重置暗码
  1. mysql> alter user root@'localhost' identified by 'mysql';
  2. ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement
  3. mysql> exit
  4. Bye
复制代码
居然不能改。。。于是:
  1. mysql> delete from mysql.user where user='root';
  2. Query OK, 1 row affected (0.10 sec)
  3. mysql> flush privileges;
  4. Query OK, 0 rows affected (0.00 sec)
  5. mysql> create user root@'localhost' identified by 'mysql';
  6. ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
复制代码
还是不能改,查看暗码复杂度要求:
  1. mysql> show variables like '%pass%';
  2. +----------------------------------------------+-----------------+
  3. | Variable_name                | Value      |
  4. +----------------------------------------------+-----------------+
  5. | caching_sha2_password_auto_generate_rsa_keys | ON       |
  6. | caching_sha2_password_private_key_path    | private_key.pem |
  7. | caching_sha2_password_public_key_path    | public_key.pem |
  8. | default_password_lifetime          | 0        |
  9. | disconnect_on_expired_password        | ON       |
  10. | mysql_native_password_proxy_users      | OFF       |
  11. | password_history               | 0        |
  12. | password_reuse_interval           | 0        |
  13. | report_password               |         |
  14. | sha256_password_auto_generate_rsa_keys    | ON       |
  15. | sha256_password_private_key_path       | private_key.pem |
  16. | sha256_password_proxy_users         | OFF       |
  17. | sha256_password_public_key_path       | public_key.pem |
  18. | validate_password.check_user_name      | ON       |
  19. | validate_password.dictionary_file      |         |
  20. | validate_password.length           | 8        |
  21. | validate_password.mixed_case_count      | 1        |
  22. | validate_password.number_count        | 1        |
  23. | validate_password.policy           | MEDIUM     |
  24. | validate_password.special_char_count     | 1        |
  25. +----------------------------------------------+-----------------+
复制代码
查看官网https://dev.mysql.com/doc/refman/8.0/en/validate-password-options-variables.html#sysvar_validate_password.policy
发现此值有3个,如下所示:

于是设置为0,然后将validate_password.length设置为4,表示最少必要4字符。之以是设置为4是由于这个参数的值不能小于如下公式的盘算结果:
  1. validate_password.number_count
  2. + validate_password.special_char_count
  3. + (2 * validate_password.mixed_case_count)
复制代码
于是继续创建用户,MySQL8.0取消了直接grant创建用户的语法,只能先create user再grant,因此创建root如下:
  1. mysql> create user root@'localhost' identified by 'mysql';
  2. ERROR 1396 (HY000): Operation CREATE USER failed for 'root'@'localhost'
  3. mysql> FLUSH PRIVILEGES;
  4. Query OK, 0 rows affected (0.00 sec)
  5. mysql> create user root@'localhost' identified by 'mysql';
  6. ERROR 1396 (HY000): Operation CREATE USER failed for 'root'@'localhost'
复制代码
尼玛...什么玩意儿?
于是去逛了一圈stackoverflow,都说这是一个BUG,于是操作如下:
  1. mysql> drop user root@'localhost';  --是的没错,虽然没有root@'localhost'用户,但你还是要删一遍。
  2. Query OK, 0 rows affected (0.05 sec)
  3. mysql> FLUSH PRIVILEGES;
  4. Query OK, 0 rows affected (0.01 sec)
  5. mysql> create user root@'localhost' identified by 'mysql';
  6. Query OK, 0 rows affected (0.03 sec)
  7. mysql> grant all on *.* to root@'localhost' with grant option;
  8. Query OK, 0 rows affected (0.03 sec)
复制代码
终于改完暗码了...去掉参数文件的skip-grant-tables参数,service mysqld restart重启服务。
五、终于设置好暗码了,建一个测试用户leo,然后实验远程连接下吧:
  1. $ mysql -uleo -pmysql -h192.168.1.193
  2. mysql: [Warning] Using a password on the command line interface can be insecure.
  3. 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工具都连不上,这就尴尬了,查看认证相关参数:
  1. mysql> show variables like '%auth%';
  2. +-------------------------------+-----------------------+
  3. | Variable_name         | Value         |
  4. +-------------------------------+-----------------------+
  5. | default_authentication_plugin | caching_sha2_password |
  6. +-------------------------------+-----------------------+
  7. 1 row in set (0.02 sec)
复制代码
查看官网发现此值的取值如下:

官网还说此值影响create user不显式指定auth plugin时暗码的默认加密算法,卧槽...那岂不是说我之前创建的leo用户使用的是默认的caching_sha2_password认证,查看一下:
  1. mysql> select user,host,plugin from mysql.user;
  2. +------------------+-----------+-----------------------+
  3. | user       | host   | plugin        |
  4. +------------------+-----------+-----------------------+
  5. | leo       | %     | caching_sha2_password |
  6. | mysql.infoschema | localhost | mysql_native_password |
  7. | mysql.session  | localhost | mysql_native_password |
  8. | mysql.sys    | localhost | mysql_native_password |
  9. | root       | localhost | caching_sha2_password |
  10. +------------------+-----------+-----------------------+
复制代码
完了,全TM完了......
显然不能直接update plugin,由于这可能导致加密的暗码无法被正确解密,你所有的暗码都会变异,因此除root@'localhost'外全部删掉重建。
首先必要在my.cnf里添加:default_authentication_plugin=mysql_native_password,然后service mysqld restart重启服务:
  1. mysql> drop user leo;
  2. Query OK, 0 rows affected (0.10 sec)
  3. mysql> flush privileges;
  4. Query OK, 0 rows affected (0.00 sec)
  5. mysql> create user leo identified by 'mysql';
  6. Query OK, 0 rows affected (0.02 sec)
  7. mysql> grant all on *.* to leo;
  8. Query OK, 0 rows affected (0.08 sec)
  9. $mysql -V
  10. mysql Ver 14.14 Distrib 5.7.20, for Linux (x86_64) using EditLine wrapper
  11. $ mysql -uleo -pmysql -h192.168.1.193
  12. mysql: [Warning] Using a password on the command line interface can be insecure.
  13. Welcome to the MySQL monitor. Commands end with ; or \g.
  14. Your MySQL connection id is 16
  15. Server version: 8.0.11 MySQL Community Server - GPL
  16. Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
  17. Oracle is a registered trademark of Oracle Corporation and/or its
  18. affiliates. Other names may be trademarks of their respective
  19. owners.
  20. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  21. mysql>
复制代码
至此远程连接正常。
总结
以上所述是小编给各人介绍的MySql 8.0.11安装配置教程,希望对各人有所资助,假如各人有任何疑问请给我留言,小编会实时复兴各人的。在此也非常感谢各人对草根技能分享网站的支持!

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x

帖子地址: 

回复

使用道具 举报

分享
推广
火星云矿 | 预约S19Pro,享500抵1000!
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

草根技术分享(草根吧)是全球知名中文IT技术交流平台,创建于2021年,包含原创博客、精品问答、职业培训、技术社区、资源下载等产品服务,提供原创、优质、完整内容的专业IT技术开发社区。
  • 官方手机版

  • 微信公众号

  • 商务合作