Linux安装MySQL8.0.12之二进制安装

时间:2022-02-19 18:50:45

运行环境:centos 7.5 + mysql8.0.12

1.下载官方打包好的二进制安装包:

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

2.解压文件:

tar -xJvf mysql-8.0.-linux-glibc2.-x86_64.tar.xz -C /usr/local/
mv /usr/local/mysql-8.0.-linux-glibc2.-x86_64/ /usr/local/mysql

3.创建目录授权

groupadd mysql
useradd mysql mkdir -p /usr/local/mysql/
mkdir -p /usr/local/mysql/data
mkdir -p /usr/local/mysql/etc
mkdir -p /usr/local/mysql/log chown -R mysql:mysql /usr/local/mysql/

4.配置参数文件:

cat > /usr/local/mysql/etc/my.cnf << EOF
[client]
port =
socket = /usr/local/mysql/data/mysql.sock
[mysqld]
server-id =
port =
mysqlx_port =
mysqlx_socket = /usr/local/mysql/data/mysqlx.sock
datadir = /usr/local/mysql/data
socket = /usr/local/mysql/data/mysql.sock
pid-file = /usr/local/mysql/data/mysqld.pid
log-error = error.log
slow-query-log =
slow-query-log-file = slow.log
long_query_time = 0.2
log-bin = bin.log
relay-log = relay.log
binlog_format =ROW
relay_log_recovery =
character-set-client-handshake = FALSE
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
init_connect ='SET NAMES utf8mb4'
innodb_buffer_pool_size = 1G
join_buffer_size = 128M
sort_buffer_size = 2M
read_rnd_buffer_size = 2M
log_timestamps = SYSTEM
lower_case_table_names =
default-authentication-plugin =mysql_native_password EOF

5.初始化数据库:

/usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql 
cat /usr/local/mysql/data/error.log | grep -i password

6.设置启动文件和环境变量:

cp /usr/local/mysql/support-files/mysql.server  /etc/init.d/mysql
chkconfig --add mysql
chkconfig --list
systemctl start mysql

7.设置可以远程登录的账号:

mysql> show variables like '%valid%pass%';
Empty set (0.00 sec)
mysql> create user root@'%' identified by 'abc123';
ERROR (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement
mysql> show variables like '%valid%pass%';
ERROR (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql> alter user root@'localhost' identified by 'abc123';
Query OK, rows affected (0.07 sec)
mysql> show variables like '%valid%pass%';
Empty set (0.01 sec)
--创建可以远程登录的用户:
mysql> create user root@'%' identified by 'abc123';
Query OK, rows affected (0.06 sec)
mysql> grant all privileges on *.* to root@'%' with grant option;
Query OK, rows affected (0.07 sec)
mysql> flush privileges;
Query OK, rows affected (0.00 sec)