CentOS7 二进制安装MySQL8.0.12

1、安装依赖

yum install gcc gcc-c++ openssl openssl-devel libaio libaio-devel  ncurses  ncurses-devel

2、下载MySQL8二进制文件包

wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.12-linux-glibc2.12-x86_64.tar

3、解压

tar vxf mysql-8.0.12-linux-glibc2.12-x86_64.tar

解压后会得出两个文件:

  • mysql-test-8.0.12-linux-glibc2.12-x86_64.tar.xz
  • mysql-8.0.12-linux-glibc2.12-x86_64.tar.xz

再解压 mysql-8.0.12-linux-glibc2.12-x86_64.tar.xz 文件至 /usr/src目录,并重命令目录为mysql

tar vxf mysql-8.0.12-linux-glibc2.12-x86_64.tar.xz -C /usr/src
mv /usr/src/mysql-8.0.12-linux-glibc2.12-x86_64 /usr/src/mysql
ln -s /usr/src/mysql /usr/local/mysql

4、创建目录

  • /mnt/mydatas    数据目录
  • /var/log/mysql-err.log 错误日志
  • /var/log/mariadb/mysql.log  MySQL日志
  • /var/run/mariadb 
mkdir /mnt/mydatas
mkdir /var/log/mariadb
mkdir /var/run/mariadb

touch /var/log/mysql-err.log
touch /var/log/mariadb/mysql.log

5、添加用户组及用户

groupadd mysql
useradd -r -g mysql mysql -s /sbin/nologin
chown -R mysql:mysql /usr/src/mysql
chown -R mysql:mysql /usr/local/mysql
chown -R mysql:mysql /mnt/mydatas
chown -R mysql:mysql /var/log/mariadb
chown -R mysql:mysql /var/run/mariadb

6、初始化数据库

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

7、添加环境变量

vi /etc/profile

.....


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



source /etc/profile

8、MySQL配置文件

[mysqld]
port=3306
datadir=/mnt/mydatas
basedir=/usr/local/mysql
socket=/tmp/mysql.sock
log-error=/var/log/mysql-err.log
user=mysql
# skip-grant-tables
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
[client]
socket=/tmp/mysql.sock
[mysqld_safe]
log-error=/var/log/mariadb/mysql.log
pid-file=/var/run/mariadb/mysql.pid

#
# include all files from the config directory
#
!includedir /etc/my.cnf.d

9、制作启动脚本

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


# 设置mysqd文件中的变量值

basedir=/usr/local/mysql
datadir=/mnt/mydatas

10、启动MySQL并修改密码


service mysqld start
mysql -uroot -p
mysql> use mysql;
mysql> update user set authentication_string = '' where user = 'root';
mysql> select host,user,authentication_string,plugin from user;
mysql> exit;

# 删掉my.cnf中的 skip-grant-tables后再重启mysql
service mysqld restart
mysql -uroot -p
mysql> alter user 'root'@'localhost' identified by 'Psufool888@2018';
mysql> flush privileges;

上面可以不需要使用flush privileges,但密码必须包含:大写字母,小写字母,数字,特殊符号

11、修改IP限制

mysql> use mysql;
mysql> update user set host = '%' where user = 'root';
mysql> flush privileges;
mysql> ALTER USER 'root'@'%' IDENTIFIED BY 'Psufool888@2018' PASSWORD EXPIRE NEVER;
mysql> ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'Psufool888@2018';

 

你可能感兴趣的:(MySQL,CentOS)