暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

CentOS7安装MySQL8.0安装小计

逸鹏说道 2019-05-15
226

文章汇总:https://www.cnblogs.com/dotnetcrazy/p/9160514.html

目录:

  • 1.环境安装

  • 2.初始化配置

  • 3.权限设置

  • 4.配置相关

  • 测试

  • Shell附录

  • 1.安装附录

  • 2.初始化配置附录

  • 3.权限附录

  • 4.配置附录

之前讲配置文件和权限的时候有很多MySQL8的知识,有同志说安装不太一样,希望发个文,我这边简单演示一下

1.环境安装

下载MySQL提供的CentOS7的yum源

官方文档:<https://dev.mysql.com/doc/refman/8.0/en/>

过程中有不太懂的可以看我之前写的这篇文章:<http://www.cnblogs.com/dotnetcrazy/p/9887708.html>

 

CentOS命令:curl https://repo.mysql.com//mysql80-community-release-el7-3.noarch.rpm > centos7.mysql.rpm  下载yum源(curl是系统自带的)

安装yum源:yum install centos7.mysql.rpm -y

安装MySQL8.0 yum install mysql-community-server -y

启动mysql systemctl start mysqld

设置开机启动mysql systemctl enable mysqld

2.初始化配置

查看初始密码 cat var/log/mysqld.log | grep "password"

安全初始化 mysql_secure_installation

3.权限设置

权限相关详细可以查看上次写的文章:聊聊数据库:SQL运维~存储引擎与权限

用root账号登录 mysql -uroot -p

创建用户dnt create user dnt@'%' identified by '含大小写字母+数字的密码';

查看当前有哪些用户 select user,authentication_string,host from mysql.user

给用户dnt分配数据库dotnetcrazy的所有权限 grant all on dotnetcrazy.* to dnt;

刷新权限 flush privileges;

显示新用户有哪些权限 show grants for dnt;

 

4.配置相关

这块我就说下开远程的配置,其他的可以查看之前写的文章:<https://www.cnblogs.com/dotnetcrazy/p/10810798.html>

root权限去修改 /etc/my.cnf

[mysqld]选项下新增:bind-address=0.0.0.0

开放3306端口的远程访问权限:firewall-cmd --zone=public --add-port=3306/tcp --permanent

刷新防火墙规则 firewall-cmd --reload

重启MySQL:systemctl restart mysqld

 

测试

Shell附录

1.安装附录

  1. # 下载yum源(curl是系统自带的)

  2. # curl https://repo.mysql.com//mysql80-community-release-el7-3.noarch.rpm > centos7.mysql.rpm

  3. [root@localhost dnt] curl https://repo.mysql.com//mysql80-community-release-el7-3.noarch.rpm > centos7.mysql.rpm

  4. % Total % Received % Xferd Average Speed Time Time Time Current

  5. Dload Upload Total Spent Left Speed

  6. 100 26024 100 26024 0 0 38150 0 --:--:-- --:--:-- --:--:-- 38158

  7. [root@localhost dnt]# ls

  8. centos7.mysql.rpm

  9. # 安装MySQL的yum源

  10. # yum install centos7.mysql.rpm -y

  11. [root@localhost dnt] yum install centos7.mysql.rpm -y

  12. 已加载插件:fastestmirror

  13. 正在检查 centos7.mysql.rpm: mysql80-community-release-el7-3.noarch

  14. centos7.mysql.rpm 将被安装

  15. 正在解决依赖关系

  16. --> 正在检查事务

  17. ---> 软件包 mysql80-community-release.noarch.0.el7-3 将被 安装

  18. --> 解决依赖关系完成

  19. 依赖关系解决

  20. ==========================================================================================================

  21. Package 架构 版本 大小

  22. ==========================================================================================================

  23. 正在安装:

  24. mysql80-community-release noarch el7-3 /centos7.mysql 31 k

  25. 事务概要

  26. ==========================================================================================================

  27. 安装 1 软件包

  28. 总计:31 k

  29. 安装大小:31 k

  30. Downloading packages:

  31. Running transaction check

  32. Running transaction test

  33. Transaction test succeeded

  34. Running transaction

  35. 正在安装 : mysql80-community-release-el7-3.noarch 1/1

  36. 验证中 : mysql80-community-release-el7-3.noarch 1/1

  37. 已安装:

  38. mysql80-community-release.noarch 0:el7-3

  39. 完毕!

  40. # 安装MySQL8.0

  41. # yum install mysql-community-server -y

  42. [root@localhost dnt] yum install mysql-community-server -y

  43. 已加载插件:fastestmirror

  44. Loading mirror speeds from cached hostfile

  45. * base: mirrors.aliyun.com

  46. * extras: mirrors.cn99.com

  47. * updates: mirrors.aliyun.com

  48. base | 3.6 kB 00:00:00

  49. extras | 3.4 kB 00:00:00

  50. mysql-connectors-community | 2.5 kB 00:00:00

  51. mysql-tools-community | 2.5 kB 00:00:00

  52. mysql80-community | 2.5 kB 00:00:00

  53. updates | 3.4 kB 00:00:00

  54. (1/3): mysql-connectors-community/x86_64/primary_db | 41 kB 00:00:00

  55. (2/3): mysql80-community/x86_64/primary_db | 70 kB 00:00:00

  56. (3/3): mysql-tools-community/x86_64/primary_db | 58 kB 00:00:00

  57. 正在解决依赖关系

  58. --> 正在检查事务

  59. ---> 软件包 mysql-community-server.x86_64.0.8.0.16-2.el7 将被 安装

  60. --> 正在处理依赖关系 mysql-community-common(x86-64) = 8.0.16-2.el7,它被软件包 mysql-community-server-8.0.16-2.el7.x86_64 需要

  61. --> 正在处理依赖关系 mysql-community-client(x86-64) >= 8.0.11,它被软件包 mysql-community-server-8.0.16-2.el7.x86_64 需要

  62. --> 正在处理依赖关系 net-tools,它被软件包 mysql-community-server-8.0.16-2.el7.x86_64 需要

  63. --> 正在检查事务

  64. ---> 软件包 mysql-community-client.x86_64.0.8.0.16-2.el7 将被 安装

  65. --> 正在处理依赖关系 mysql-community-libs(x86-64) >= 8.0.11,它被软件包 mysql-community-client-8.0.16-2.el7.x86_64 需要

  66. ---> 软件包 mysql-community-common.x86_64.0.8.0.16-2.el7 将被 安装

  67. ---> 软件包 net-tools.x86_64.0.2.0-0.24.20131004git.el7 将被 安装

  68. --> 正在检查事务

  69. ---> 软件包 mariadb-libs.x86_64.1.5.5.60-1.el7_5 将被 取代

  70. --> 正在处理依赖关系 libmysqlclient.so.18()(64bit),它被软件包 2:postfix-2.10.1-7.el7.x86_64 需要

  71. --> 正在处理依赖关系 libmysqlclient.so.18(libmysqlclient_18)(64bit),它被软件包 2:postfix-2.10.1-7.el7.x86_64 需要

  72. ---> 软件包 mysql-community-libs.x86_64.0.8.0.16-2.el7 将被 舍弃

  73. --> 正在检查事务

  74. ---> 软件包 mysql-community-libs-compat.x86_64.0.8.0.16-2.el7 将被 舍弃

  75. --> 解决依赖关系完成

  76. 依赖关系解决

  77. ==========================================================================================================

  78. Package 架构 版本 大小

  79. ==========================================================================================================

  80. 正在安装:

  81. mysql-community-libs x86_64 8.0.16-2.el7 mysql80-community 3.0 M

  82. 替换 mariadb-libs.x86_64 1:5.5.60-1.el7_5

  83. mysql-community-libs-compat x86_64 8.0.16-2.el7 mysql80-community 2.1 M

  84. 替换 mariadb-libs.x86_64 1:5.5.60-1.el7_5

  85. mysql-community-server x86_64 8.0.16-2.el7 mysql80-community 403 M

  86. 为依赖而安装:

  87. mysql-community-client x86_64 8.0.16-2.el7 mysql80-community 32 M

  88. mysql-community-common x86_64 8.0.16-2.el7 mysql80-community 575 k

  89. net-tools x86_64 2.0-0.24.20131004git.el7 base 306 k

  90. 事务概要

  91. ==========================================================================================================

  92. 安装 3 软件包 (+3 依赖软件包)

  93. 总下载量:441 M

  94. Downloading packages:

  95. 警告:/var/cache/yum/x86_64/7/mysql80-community/packages/mysql-community-common-8.0.16-2.el7.x86_64.rpm: V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY

  96. mysql-community-common-8.0.16-2.el7.x86_64.rpm 的公钥尚未安装

  97. (1/6): mysql-community-common-8.0.16-2.el7.x86_64.rpm | 575 kB 00:00:00

  98. (2/6): mysql-community-libs-8.0.16-2.el7.x86_64.rpm | 3.0 MB 00:00:00

  99. (3/6): mysql-community-libs-compat-8.0.16-2.el7.x86_64.rpm | 2.1 MB 00:00:00

  100. (4/6): net-tools-2.0-0.24.20131004git.el7.x86_64.rpm | 306 kB 00:00:00

  101. (5/6): mysql-community-client-8.0.16-2.el7.x86_64.rpm | 32 MB 00:00:14

  102. (6/6): mysql-community-server-8.0.16-2.el7.x86_64.rpm | 403 MB 00:01:08

  103. -------------------------------------------------------------------------------------------------------------------

  104. 总计 6.2 MB/s | 441 MB 00:01:10

  105. file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql 检索密钥

  106. 导入 GPG key 0x5072E1F5:

  107. 用户ID : "MySQL Release Engineering <mysql-build@oss.oracle.com>"

  108. 指纹 : a4a9 4068 76fc bd3c 4567 70c8 8c71 8d3b 5072 e1f5

  109. 软件包 : mysql80-community-release-el7-3.noarch (installed)

  110. 来自 : /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

  111. Running transaction check

  112. Running transaction test

  113. Transaction test succeeded

  114. Running transaction

  115. 正在安装 : mysql-community-common-8.0.16-2.el7.x86_64 1/7

  116. 正在安装 : mysql-community-libs-8.0.16-2.el7.x86_64 2/7

  117. 正在安装 : mysql-community-client-8.0.16-2.el7.x86_64 3/7

  118. 正在安装 : net-tools-2.0-0.24.20131004git.el7.x86_64 4/7

  119. 正在安装 : mysql-community-server-8.0.16-2.el7.x86_64 5/7

  120. 正在安装 : mysql-community-libs-compat-8.0.16-2.el7.x86_64 6/7

  121. 正在删除 : 1:mariadb-libs-5.5.60-1.el7_5.x86_64 7/7

  122. 验证中 : mysql-community-libs-8.0.16-2.el7.x86_64 1/7

  123. 验证中 : net-tools-2.0-0.24.20131004git.el7.x86_64 2/7

  124. 验证中 : mysql-community-libs-compat-8.0.16-2.el7.x86_64 3/7

  125. 验证中 : mysql-community-client-8.0.16-2.el7.x86_64 4/7

  126. 验证中 : mysql-community-common-8.0.16-2.el7.x86_64 5/7

  127. 验证中 : mysql-community-server-8.0.16-2.el7.x86_64 6/7

  128. 验证中 : 1:mariadb-libs-5.5.60-1.el7_5.x86_64 7/7

  129. 已安装:

  130. mysql-community-libs.x86_64 0:8.0.16-2.el7 mysql-community-libs-compat.x86_64 0:8.0.16-2.el7

  131. mysql-community-server.x86_64 0:8.0.16-2.el7

  132. 作为依赖被安装:

  133. mysql-community-client.x86_64 0:8.0.16-2.el7 mysql-community-common.x86_64 0:8.0.16-2.el7

  134. net-tools.x86_64 0:2.0-0.24.20131004git.el7

  135. 替代:

  136. mariadb-libs.x86_64 1:5.5.60-1.el7_5

  137. 完毕!

  138. # 启动mysql

  139. # systemctl start mysqld

  140. [root@localhost dnt] systemctl start mysqld

  141. [root@localhost dnt] pstree | grep mysql

  142. |-mysqld---37*[{mysqld}]

  143. # 设置开机启动mysql

  144. # systemctl enable mysqld

  145. [root@localhost dnt] systemctl enable mysqld

  146. [root@localhost dnt] reboot

  147. Connection closing...Socket close.

  148. Connection closed by foreign host.

  149. Disconnected from remote host(MySQL_CentOS) at 10:56:42.

  150. Connecting to 192.168.36.205:22...

  151. Connection established.

  152. To escape to local shell, press 'Ctrl+Alt+]'.

  153. WARNING! The remote SSH server rejected X11 forwarding request.

  154. Last login: Wed May 15 10:35:07 2019 from 192.168.36.144

  155. [dnt@localhost ~]$ pstree | grep mysql

  156. |-mysqld---37*[{mysqld}]

  157. # 查看mysql的状态

  158. # systemctl status mysqld

  159. [dnt@localhost ~]$ systemctl status mysqld

  160. mysqld.service - MySQL Server

  161. Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)

  162. Active: active (running) since 2019-05-15 10:57:26 CST; 1min 3s ago

  163. Docs: man:mysqld(8)

  164. http://dev.mysql.com/doc/refman/en/using-systemd.html

  165. Process: 3934 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)

  166. Main PID: 3969 (mysqld)

  167. Status: "SERVER_OPERATING"

  168. CGroup: /system.slice/mysqld.service

  169. └─3969 /usr/sbin/mysqld

2.初始化配置附录

  1. # 查看初始密码

  2. # cat /var/log/mysqld.log | grep "password"

  3. [dnt@localhost ~]$ cat /var/log/mysqld.log | grep "password"

  4. 2019-05-15T02:55:51.132377Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: wI>X.(tHE5&e

  5. # 安全初始化

  6. # mysql_secure_installation

  7. [dnt@localhost ~]$ mysql_secure_installation

  8. Securing the MySQL server deployment.

  9. Enter password for user root:

  10. The 'validate_password' component is installed on the server.

  11. The subsequent steps will run with the existing configuration

  12. of the component.

  13. Using existing password for root.

  14. Estimated strength of the password: 100

  15. Change the password for root ? ((Press y|Y for Yes, any other key for No) : n

  16. ... skipping.

  17. By default, a MySQL installation has an anonymous user,

  18. allowing anyone to log into MySQL without having to have

  19. a user account created for them. This is intended only for

  20. testing, and to make the installation go a bit smoother.

  21. You should remove them before moving into a production

  22. environment.

  23. Remove anonymous users? (Press y|Y for Yes, any other key for No) : y

  24. Success.

  25. Normally, root should only be allowed to connect from

  26. 'localhost'. This ensures that someone cannot guess at

  27. the root password from the network.

  28. Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y

  29. Success.

  30. By default, MySQL comes with a database named 'test' that

  31. anyone can access. This is also intended only for testing,

  32. and should be removed before moving into a production

  33. environment.

  34. Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y

  35. - Dropping test database...

  36. Success.

  37. - Removing privileges on test database...

  38. Success.

  39. Reloading the privilege tables will ensure that all changes

  40. made so far will take effect immediately.

  41. Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y

  42. Success.

  43. All done!

3.权限附录

  1. # 用root账号登录

  2. # mysql -uroot -p

  3. [dnt@localhost ~]$ mysql -uroot -p

  4. Enter password:

  5. Welcome to the MySQL monitor. Commands end with ; or \g.

  6. Your MySQL connection id is 38

  7. Server version: 8.0.16 MySQL Community Server - GPL

  8. Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

  9. Oracle is a registered trademark of Oracle Corporation and/or its

  10. affiliates. Other names may be trademarks of their respective

  11. owners.

  12. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

  13. # show databases;

  14. mysql> show databases;

  15. +--------------------+

  16. | Database |

  17. +--------------------+

  18. | information_schema |

  19. | mysql |

  20. | performance_schema |

  21. | sys |

  22. +--------------------+

  23. 4 rows in set (0.00 sec)

  24. # 创建用户dnt

  25. # create user dnt@'%' identified by '含大小写字母+数字的密码';

  26. mysql> create user dnt@'%' identified by '含大小写字母+数字的密码';

  27. Query OK, 0 rows affected (0.06 sec)

  28. # 查看当前有哪些用户

  29. # select user,authentication_string,host from mysql.user;

  30. mysql> select user,authentication_string,host from mysql.user;

  31. +------------------+------------------------------------------------------------------------+-----------+

  32. | user | authentication_string | host |

  33. +------------------+------------------------------------------------------------------------+-----------+

  34. | dnt | $A$005$yOK}8VFp< LE0BLBPFmeTy2vi8Q1JdmkhkPkaWBilxWYW2/jSsJ4OEa7B | % |

  35. | mysql.infoschema | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | localhost |

  36. | mysql.session | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | localhost |

  37. | mysql.sys | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | localhost |

  38. | root | $A$005$yAn@!RwTRzRLdyRrHMdoneUh7pdKEJVFUl9LHdG5MHeL.gdovFMI7z22 | localhost |

  39. +------------------+------------------------------------------------------------------------+-----------+

  40. 5 rows in set (0.00 sec)

  41. # 创建一个数据库

  42. # create database dotnetcrazy charset=utf8;

  43. mysql> create database dotnetcrazy charset=utf8;

  44. Query OK, 1 row affected, 1 warning (0.71 sec)

  45. mysql> show databases;

  46. +--------------------+

  47. | Database |

  48. +--------------------+

  49. | dotnetcrazy |

  50. | information_schema |

  51. | mysql |

  52. | performance_schema |

  53. | sys |

  54. +--------------------+

  55. 5 rows in set (0.00 sec)

  56. # 给用户dnt分配数据库dotnetcrazy的所有权限

  57. # grant all on dotnetcrazy.* to dnt;

  58. mysql> grant all on dotnetcrazy.* to dnt;

  59. Query OK, 0 rows affected (0.69 sec)

  60. # 刷新权限

  61. # flush privileges;

  62. mysql> flush privileges;

  63. Query OK, 0 rows affected (0.59 sec)

  64. # 显示新用户有哪些权限

  65. # show grants for dnt;

  66. mysql> show grants for dnt;

  67. +------------------------------------------------------+

  68. | Grants for dnt@% |

  69. +------------------------------------------------------+

  70. | GRANT USAGE ON *.* TO `dnt`@`%` |

  71. | GRANT ALL PRIVILEGES ON `dotnetcrazy`.* TO `dnt`@`%` |

  72. +------------------------------------------------------+

  73. 2 rows in set (0.00 sec)

  74. mysql> exit

  75. Bye

  76. # 用新增用户登录

  77. # mysql -udnt -p

  78. [dnt@localhost ~]$ mysql -udnt -p

  79. Enter password:

  80. Welcome to the MySQL monitor. Commands end with ; or \g.

  81. Your MySQL connection id is 39

  82. Server version: 8.0.16 MySQL Community Server - GPL

  83. Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

  84. Oracle is a registered trademark of Oracle Corporation and/or its

  85. affiliates. Other names may be trademarks of their respective

  86. owners.

  87. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

  88. # show databases;

  89. mysql> show databases;

  90. +--------------------+

  91. | Database |

  92. +--------------------+

  93. | dotnetcrazy |

  94. | information_schema |

  95. +--------------------+

  96. 2 rows in set (0.01 sec)

4.配置附录

  1. [dnt@localhost ~]$ su

  2. 密码:

  3. [root@localhost dnt]# ls /etc/ | grep my

  4. my.cnf

  5. my.cnf.d

  6. [root@localhost dnt]# ls /etc/my.cnf.d/

  7. # 修改配置,运行远程登录

  8. [root@localhost dnt]# vi /etc/my.cnf

  9. [root@localhost dnt]# cat /etc/my.cnf

  10. [mysqld]

  11. bind-address=0.0.0.0 # 新增内容

  12. datadir=/var/lib/mysql

  13. socket=/var/lib/mysql/mysql.sock

  14. log-error=/var/log/mysqld.log

  15. pid-file=/var/run/mysqld/mysqld.pid

  16. # 查看一下防火墙状态

  17. # systemctl status firewalld

  18. [root@localhost dnt] systemctl status firewalld

  19. firewalld.service - firewalld - dynamic firewall daemon

  20. Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)

  21. Active: active (running) since 2019-05-15 17:37:49 CST; 28min ago

  22. Docs: man:firewalld(1)

  23. Main PID: 3467 (firewalld)

  24. CGroup: /system.slice/firewalld.service

  25. └─3467 /usr/bin/python -Es /usr/sbin/firewalld --nofork --nopid

  26. 5 15 17:37:47 localhost.localdomain systemd[1]: Starting firewalld - dynamic firewall daemon...

  27. 5 15 17:37:49 localhost.localdomain systemd[1]: Started firewalld - dynamic firewall daemon.

  28. # 开放3306端口的远程访问权限

  29. # firewall-cmd --zone=public --add-port=3306/tcp --permanent

  30. [root@localhost dnt]# firewall-cmd --zone=public --add-port=3306/tcp --permanent

  31. success

  32. # 刷新防火墙规则

  33. # firewall-cmd --reload

  34. [root@localhost dnt]# firewall-cmd --reload

  35. success

  36. # 重启MySQL

  37. # systemctl restart mysqld

  38. [root@localhost dnt]# systemctl restart mysqld


下节预估:MySQL日志篇

文章转载自逸鹏说道,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论