centos7 安装mysql8

系统环境:centos7.5,mysql版本:8.0.13,安装方式:解压安装。
1.下载mysql8.0.13解压包。点击download获取下载地址后在centos7用wget下载。


mysql官网下载界面
[root@litie143 ~]# wget https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.13-el7-x86_64.tar.gz
--2018-11-16 10:03:24--  https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.13-el7-x86_64.tar.gz
Resolving cdn.mysql.com (cdn.mysql.com)... 23.217.125.65
Connecting to cdn.mysql.com (cdn.mysql.com)|23.217.125.65|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 657877489 (627M) [application/x-tar-gz]
Saving to: `mysql-8.0.13-el7-x86_64.tar.gz`
92% [==============================================================================================================>          ] 608,267,232 31.2KB/s  eta 3m 8s

2.解压下载的mysql包。

[root@litie143 ~]# ll
-rw-r--r--. 1 root root 657877489 Oct  7 16:18 mysql-8.0.13-el7-x86_64.tar.gz
[root@litie143 ~]# tar xvf mysql-8.0.13-el7-x86_64.tar.gz
[root@litie143 ~]# ll
drwxr-xr-x. 9 root root       172 Nov 16 11:04 mysql-8.0.13-el7-x86_64
-rw-r--r--. 1 root root 657877489 Oct  7 16:18 mysql-8.0.13-el7-x86_64.tar.gz
[root@litie143 ~]# 

3.创建MySQL用户组及用户

[root@litie143 ~]# groupadd mysql
[root@litie143 ~]# useradd -r -g mysql -s /bin/false mysql

4.把解压的mysql文件夹拷贝到/usr/local/mysql8。
/usr/local路径通常存放自己安装的程序,mysql文件夹名称可以自己指定,我在这里使用mysql8。

[root@litie143 ~]# mv mysql-8.0.13-el7-x86_64 /usr/local/mysql8
[root@litie143 ~]# ll /usr/local/mysql8
total 448
drwxr-xr-x.  2 root root    4096 Nov 16 11:04 bin
drwxr-xr-x.  2 root root      86 Nov 16 11:04 docs
drwxr-xr-x.  3 root root     266 Nov 16 11:04 include
drwxr-xr-x.  6 root root    4096 Nov 16 11:04 lib
-rw-r--r--.  1 7161 31415 335809 Oct  7 16:44 LICENSE
-rw-r--r--.  1 7161 31415 101807 Oct  7 16:44 LICENSE.router
drwxr-xr-x.  4 root root      30 Nov 16 11:04 man
-rw-r--r--.  1 7161 31415    687 Oct  7 16:44 README
-rw-r--r--.  1 7161 31415    700 Oct  7 16:44 README.router
drwxr-xr-x. 28 root root    4096 Nov 16 11:04 share
drwxr-xr-x.  2 root root      90 Nov 16 11:04 support-files
[root@litie143 ~]# 

5.在mysql8文件夹下创建mysql-files目录,权限设置为750,并将整个mysql8目录授权给mysql用户组

[root@litie143 ~]# cd /usr/local/mysql8
[root@litie143 mysql8]# mkdir mysql-files
[root@litie143 mysql8]# cd ..
[root@litie143 local]# chown -R mysql:mysql mysql8
[root@litie143 local]# cd mysql8
[root@litie143 mysql8]# chmod 750 mysql-files

6.在/etc目录下创建并编辑my.cnf 文件。并授权给mysql用户组

[root@litie143 mysql8]# touch /etc/my.cnf
[root@litie143 mysql8]# chown mysql:mysql /etc/my.cnf

#我的 my.cnf 大致内容如下
#
# FromDual configuration file template for MySQL, Galera Cluster, MariaDB and Percona Server
# Location: /etc/my.cnf or /etc/mysql/my.cnf
# Get most recent updated from here:
# http://www.fromdual.com/mysql-configuration-file-sample
#
[client]
port=3306

[mysqld_safe]
log-error=/var/log/mysql/mysql.log # 需要手动创建并给mysql用户组授权

[mysqld]
basedir=/usr/local/mysql8
datadir=/usr/local/mysql8/data
tmpdir=/tmp
socket=/tmp/mysql.sock # 需要手动创建并给mysql用户组授权
pid-file=/var/lib/mysql/mysql.pid # 需要手动创建并给mysql用户组授权
  1. 初始化数据库
[root@litie143 mysql8]# bin/mysqld --user=mysql --initialize
2018-11-16T07:17:29.381576Z 0 [System] [MY-013169] [Server] /usr/local/mysql8/bin/mysqld (mysqld 8.0.13) initializing of server in progress as process 1235
2018-11-16T07:17:31.735711Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: qs/c9Y%!Y!lb
2018-11-16T07:17:32.991008Z 0 [System] [MY-013170] [Server] /usr/local/mysql8/bin/mysqld (mysqld 8.0.13) initializing of server has completed

记住log中的密码,比如我的是root@localhost: qs/c9Y%!Y!lb,
密码就是:qs/c9Y%!Y!lb
如果不显示这个log,到log文件中查找。

8.创建软连接并设置开机启动

[root@litie143 mysql8]#ln -s /usr/local/mysql8/bin/mysql /usr/bin/mysql
[root@litie143 mysql8]#cp /usr/local/mysql8/support-files/mysql.server /etc/init.d/mysqld
[root@litie143 mysql8]#/sbin/chkconfig mysqld on

9.启动数据库,登陆并修改密码。密码是log中提到那个。

[root@litie143 mysql8]#systemctl start mysql.service
#登陆
[root@litie143 ~]# mysql -u root -p
Enter password:

#修改密码
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
#修改密码也可以用mysql_native_password
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';

#添加远程访问用户,用户名root,也可以自己命名。%表示所有ip可以访问
mysql> CREATE USER 'root'@'%' IDENTIFIED BY '123456';
#给'root'@'%' 用户所有mysql权限
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;  
#刷新权限
mysql> FLUSH PRIVILEGES;
  1. 防火墙开启3306端口,并重启防火墙
[root@litie143 ~]# firewall-cmd --zone=public --add-port=3306/tcp --permanent
[root@litie143 ~]# firewall-cmd --reload

你可能感兴趣的:(centos7 安装mysql8)