CentOS7 安装 MySQL8

in TCEHLinuxMySQL with 0 comment

一、下载

1.从官网下载MySQL8对应编译包到Centos7系统上

2.解压程序包

tar  -zxvf  mysql-8.0.11-el1-x86_64.tar.gz 

3.移动

mkdir /usr/local/mysql
mv  mysql-8.0.11-el1-x86_64/*  /usr/local/mysql
cd  /usr/local/mysql

二、配置

1.添加用户组

groupadd mysql

2.添加用户

useradd -r -g mysql mysql

3.更改用户组

chown -R mysql:mysql ./

4.配置my.cnf

vi /etc/my.cnf

将里面内容改为

[mysqld]
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
port=3306
socket=/tmp/mysql.sock
[mysqld_safe]
pid-file=/usr/local/mysql/data/$hostname.pid

5.初始化mysql

 bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

6.配置环境变量

vi /etc/profile

文件尾部追加

MYSQL_HOME=/usr/local/mysql
export PATH=$PATH:$MYSQL_HOME/lib:$MYSQL_HOME/bin

使环境变量生效

source /etc/profile

7.配置开机启动

 cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql

 chmod +x /etc/init.d/mysql

 chkconfig --add mysql

三、启动

 service mysql start

四、测试

1.本地测试

使用上面的临时密码登录

mysql -uroot -p

修改root密码

 ALTER USER 'root'@'localhost' IDENTIFIED BY 'root';

2.远程测试

创建远程账户

 CREATE USER 'remote'@'%' IDENTIFIED WITH MYSQL_NATIVE_PASSWORD BY  'as.200';

修改远程账户权限

 GRANT ALL ON *.* TO 'remote'@'%';

刷新权限

 FLUSH PRIVILEGES;

最后开放3306端口

firewall-cmd --zone=public --add-port=3306/tcp --permanent
firewall-cmd --reload

可使用Navicat或SQLyog进行连接测试。

Comments are closed.