Centos7安装MySQL8

一、下载

注意下载二进制包,解压可以直接使用的,这里安装最新版本8.0.17

wget https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.17-linux-glibc2.12-x86_64.tar.xz

二、基础环境设置

useradd -r mysql
mkdir -pv /soft/
mkdir  -pv /data/mysqldata/node1/log
tar -xf mysql-8.0.17-linux-glibc2.12-x86_64.tar.xz
mv mysql-8.0.17-linux-glibc2.12-x86_64 /soft/mysql
touch /data/mysqldata/node1/log/mysql.err
chown -R mysql.mysql /soft/mysql
chown -R mysql.mysql /data/mysqldata

三、初始化

$/soft/mysql/bin/mysqld -I --user=mysql --basedir=/soft/mysql --datadir=/data/mysqldata/node1

2019-09-29T08:52:14.894707Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
2019-09-29T08:52:14.894931Z 0 [System] [MY-013169] [Server] /soft/mysql/bin/mysqld (mysqld 8.0.17) initializing of server in progress as process 3278
2019-09-29T08:52:18.243191Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: geXg5X90bE?W -mysql8默认密码
2019-09-29T08:52:19.909851Z 0 [System] [MY-013170] [Server] /soft/mysql/bin/mysqld (mysqld 8.0.17) initializing of server has completed

四、配置文件

1.创建配置文件

vim my.cnf
[client]
socket=/tmp/mysql-node1.sock

[mysql]
log-error=/data/mysqldata/node1/log/mysql.err

[mysqld]
basedir=/soft/mysql
datadir=/data/mysqldata/node1
socket=/tmp/mysql-node1.sock
port=33066
user=mysql
log_timestamps=SYSTEM
default_authentication_plugin= mysql_native_password
log-error=/data/mysqldata/node1/log/mysql.err

[mysqld_safe]
log-error=/data/mysqldata/node1/log/mysql.err
pid-file=/tmp/mysqld-node1.pid
socket=/tmp/mysql-node1.sock

[mysql.server]
socket=/tmp/mysql-node1.sock

[mysqladmin]
socket=/tmp/mysql-node1.sock

2.移动到对应数据库项目

mv my.cnf /data/mysqldata/node1/

3.设置环境变量

vim /etc/profile

export PATH=$PATH:/soft/mysql/bin
source /etc/profile

五、启动

1.手动启动

/soft/mysql/bin/mysqld_safe --defaults-file=/data/mysqldata/node1/my.cnf >/dev/null &

2.放入脚本

cp /soft/mysql/support-files/mysql.server /etc/init.d/mysql.server
chkconfig --add /etc/init.d/mysql.server

将mysql.server脚本里面的basedir datadir路径修改一下就可以了

systemctl start mysql.server

六、修改密码

第一次登陆要求修改密码才能操作

mysql -uroot -S /tmp/mysql-node1.sock -p pwd:geXg5X90bE?W
mysql> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

修改密码

mysql> alter user 'root'@'localhost' identified by 'FwaX63cSCWq';

你可能感兴趣的:(mysql)