MySQL 8.0 也推出一段时间了,整理一篇安装教程html
CentOS7.4系统自带mariadbnode
[root@iZ286t0wuf9Z etc]# rpm -qa|grep mariadb mariadb-libs-5.5.56-2.el7.x86_64 [root@iZ286t0wuf9Z etc]# rpm -e --nodeps mariadb-libs-5.5.56-2.el7.x86_64
部分博客须要移除 /etc/my.cnf,经实践,本要执行卸载以前/etc目录下有my.cnf和my.cnf.d,执行卸载以后已经一块儿移除了。或者能够执行下面代码:mysql
[root@iZ286t0wuf9Z etc]# rm my.cnf
或文件不存在,会提示linux
[root@iZ286t0wuf9Z etc]# rm my.cnf rm: cannot remove ‘my.cnf’: No such file or director
检查mysql是否存在sql
[root@iZ286t0wuf9Z etc]# rpm -qa | grep mysql [root@iZ286t0wuf9Z etc]#
没有任何输出表示未安装数据库
建立mysql组和用户vim
(1) 先检查是否存在centos
[root@iZ286t0wuf9Z etc]# cat /etc/group | grep mysql [root@iZ286t0wuf9Z etc]# cat /etc/passwd | grep mysql [root@iZ286t0wuf9Z etc]#
(2) 没有输出,则建立组和用户bash
[root@iZ286t0wuf9Z etc]# groupadd mysql [root@iZ286t0wuf9Z etc]# useradd -g mysql mysql [root@iZ286t0wuf9Z etc]# passwd mysql Changing password for user mysql. New password: Retype new password: passwd: all authentication tokens updated successfully. [root@iZ286t0wuf9Z etc]#
准备安装文件服务器
截图比较多,附在文章最后,点击跳转
解压安装
(1) 把mysql-8.0.13-linux-glibc2.12-x86_64.tar.xz文件移动到/usr/local/mysql目录下,假设文件在/home/ftp目录下
[root@iZ286t0wuf9Z etc]# mv /home/ftp /usr/local/mysql
(3) 解压
[root@iZ286t0wuf9Z etc]# cd /usr/local [root@iZ286t0wuf9Z local]# tar -xvJf mysql-8.0.13-linux-glibc2.12-x86_64.tar.xz mysql-8.0.13-linux-glibc2.12-x86_64/bin/myisam_ftdump mysql-8.0.13-linux-glibc2.12-x86_64/bin/myisamchk ---------- #此处省略二百多行 mysql-8.0.13-linux-glibc2.12-x86_64... ---------- mysql-8.0.13-linux-glibc2.12-x86_64/lib/libmysqlharness.so.1 mysql-8.0.13-linux-glibc2.12-x86_64/lib/libmysqlrouter.so mysql-8.0.13-linux-glibc2.12-x86_64/lib/libmysqlrouter.so.1 [root@iZ286t0wuf9Z local]# mv mysql-8.0.13-linux-glibc2.12-x86_64 mysql
更改所属的组和用户
注意每次执行的目录
[root@iZ286t0wuf9Z mysql]# mkdir data [root@iZ286t0wuf9Z mysql]# cd .. [root@iZ286t0wuf9Z local]# chown -R mysql mysql [root@iZ286t0wuf9Z local]# chgrp -R mysql mysql
准备/etc/my.cnf文件
[root@iZ286t0wuf9Z mysql]# vim /etc/my.cnf [mysql] # 设置mysql客户端默认字符集 default-character-set=utf8mb4 [mysqld] # 设置3306端口 port = 3306 # 设置mysql的安装目录 basedir=/usr/local/mysql # 设置mysql数据库的数据的存放目录 datadir=/usr/local/mysql/data # 容许最大链接数 max_connections=200 # 服务端默认编码(数据库级别) character-set-server=utf8mb4 # 建立新表时将使用的默认存储引擎 default-storage-engine=INNODB lower_case_table_names=1 max_allowed_packet=16M [root@iZ286t0wuf9Z mysql]# chown 777 /etc/my.cnf
执行初始化
[root@iZ286t0wuf9Z mysql]# bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/ -bash: bin/mysql_install_db: No such file or directory
切换到/usr/local/mysql/bin目录下,发现确实没有 mysql_install_db
,改为 bin/mysqld --initialize
[root@iZ286t0wuf9Z mysql]# bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/ bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
又报错,执行下面命令
[root@iZ286t0wuf9Z mysql]# yum install -y libaio Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile Resolving Dependencies --> Running transaction check ---> Package libaio.x86_64 0:0.3.109-13.el7 will be installed --> Finished Dependency Resolution ---------- #此处省略二十多行输出语句 ---------- Installed: libaio.x86_64 0:0.3.109-13.el7 Complete!
再执行
[root@iZ286t0wuf9Z mysql]# bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/ 2018-11-21T07:30:42.888897Z 0 [System] [MY-013169] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.13) initializing of server in progress as process 26596 2018-11-21T07:30:48.222050Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: l*JsMq=uX4>k 2018-11-21T07:30:49.788339Z 0 [System] [MY-013170] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.13) initializing of server has completed
再执行
[root@iZ286t0wuf9Z mysql]# cp ./support-files/mysql.server /etc/init.d/mysqld [root@iZ286t0wuf9Z mysql]# chmod +x /etc/init.d/mysqld
配置环境变量
在 /etc/profile 最后添加以下内容export PATH=$PATH:/usr/local/mysql/bin
[root@iZ286t0wuf9Z mysql]# vim /etc/profile ---------- #省略N行配置信息 ---------- unset i unset -f pathmunge #set mysql environment export PATH=$PATH:/usr/local/mysql/bin
使配置文件生效
[root@iZ286t0wuf9Z mysql]# source /etc/profile
启动 MySQL 服务
[root@iZ286t0wuf9Z mysql]# /etc/init.d/mysqld start Starting MySQL.Logging to '/usr/local/mysql/data/iZ286t0wuf9Z.err'. .[ OK ] [root@iZ286t0wuf9Z mysql]#
设置 MySQL 服务开机启动
此处根据参考文档用了 chkconfig 命令,但看到提示信息以后才知道,Centos 5.7开始,
在 Centos 5.7 中服务不在是用 service 这个命令来启动与中止,也再也不用 chkconfig 来设置开机启动与否!在 centos7 中全部对服务的管理都集中到了 systemctl 当中; systemctl 再也不是合以前同样依赖 /etc/init.d/ 下的脚本,它是经过配置文件来完成对服务的管理的。(参考:蒋乐兴的技术随笔)
[root@iZ286t0wuf9Z ~]# chkconfig --list Note: This output shows SysV services only and does not include native systemd services. SysV configuration data might be overridden by native systemd configuration. If you want to list systemd services use 'systemctl list-unit-files'. To see services enabled on particular target use 'systemctl list-dependencies [target]'. aegis 0:off 1:off 2:on 3:on 4:on 5:on 6:off agentwatch 0:off 1:off 2:on 3:on 4:on 5:on 6:off netconsole 0:off 1:off 2:off 3:off 4:off 5:off 6:off network 0:off 1:off 2:on 3:on 4:on 5:on 6:off
此处暂且这样采用 chkconfig 设置
[root@iZ286t0wuf9Z mysql]# chmod +x /etc/rc.d/init.d/mysqld [root@iZ286t0wuf9Z mysql]# chkconfig --add mysqld [root@iZ286t0wuf9Z mysql]# chkconfig --list mysqld [root@iZ286t0wuf9Z mysql]# chkconfig --level 35 mysqld on
执行 add 操做以后,list 中就会有 mysqld 了
[root@iZ286t0wuf9Z ~]# chkconfig --list Note: This output shows SysV services only and does not include native systemd services. SysV configuration data might be overridden by native systemd configuration. If you want to list systemd services use 'systemctl list-unit-files'. To see services enabled on particular target use 'systemctl list-dependencies [target]'. aegis 0:off 1:off 2:on 3:on 4:on 5:on 6:off agentwatch 0:off 1:off 2:on 3:on 4:on 5:on 6:off mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off netconsole 0:off 1:off 2:off 3:off 4:off 5:off 6:off network 0:off 1:off 2:on 3:on 4:on 5:on 6:off
初始化 root 密码
并没意料到此处有障碍,本人没有找到初始密码在哪里,无奈选择重置。而后重置比我预计的复杂一点,步骤太多,请参考另外一篇博客:MySQL 8.0 以上版本重置 root 用户密码
添加远程访问权限
在服务器上能够登陆 root 用户,但远程连链接会提示
1130: host 'xxx.xxx.xxx.xxx' is not allowed to connect to this MySQL server
xxx.xxx.xxx.xxx 远程客户端的IP地址,即当前客户端IP地址禁止访问。
[root@iZ286t0wuf9Z ~]# mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 8 Server version: 8.0.13 MySQL Community Server - GPL Copyright (c) 2000, 2018, 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> use mysql Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed mysql> select host,user from user; +-----------+------------------+ | host | user | +-----------+------------------+ | localhost | mysql.infoschema | | localhost | mysql.session | | localhost | mysql.sys | | localhost | root | +-----------+------------------+ 4 rows in set (0.00 sec) mysql>
查询结果显示,root容许的IP地址为localhost,修改为%便可。固然还有更复杂的设置,好比指定IP地址,或者指定IP区间,后续会再更新。
mysql> update user set host='%' where user='root'; Query OK, 1 row affected (0.03 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> flush privileges; Query OK, 0 rows affected (0.01 sec) mysql>
到这里就能够远程登陆了。
<span id="jump">附:步骤4. 准备安装文件的过程截图</span>
先整理这么多了,欢迎你们共同讨论。