CentOS 7.6下解压安装(非编译安装)mysql8.0.18

wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.18-el7-x86_64.tar.gz

1、建立mysql用户

# groupadd -r mysql

# useradd -g mysql -r -M -s /sbin/nologin mysql //这个mysql用户不能登录

2、解压安装

# tar zxvf mysql-8.0.18-el7-x86_64.tar.gz

# mv mysql-8.0.18-el7-x86_64 /mnt/local/mysql

3、修改目录权限

# cd /mnt/local/mysql/

# chown -R mysql:mysql ./ //修改当前目录为mysql用户

# mkdir -p /mnt/data/mysql

# chown -R mysql:mysql /mnt/data/mysql

# chown -R mysql:mysql /mnt/data/mysql/.

4、开始安装

# cd /mnt/local/mysql/bin

# ./mysqld --initialize --user=mysql --basedir=/mnt/local/mysql --datadir=/mnt/data/mysql/

如果报:

./mysqld: error while loading shared libraries: libnuma.so.1: cannot open shared object file: No such file or directory

解决办法为:

yum -y install numactl

如果报:

./mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory

解决办法为:

yum install libaio-devel.x86_64

5、编辑my.cnf

vim /etc/my.cnf

[mysqld]
basedir=/mnt/local/mysql
datadir=/mnt/data/mysql
socket=/tmp/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
character-set-server = utf8mb4
collation-server = utf8mb4_general_ci
port = 3369
max_connections=5000
wait_timeout=70
interactive_timeout=70
slow_query_log = 1
long-query-time = 1.0
slow_query_log_file = /mnt/logs/mysql/slow.log
sql_mode = STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION
default-authentication-plugin=mysql_native_password

[mysql]
default-character-set = utf8mb4

[client]
port=3369
max_allowed_packet=500M
socket=/tmp/mysql.sock

[mysqld_safe]
log-error=/mnt/logs/mysql/error.log
pid-file=/var/run/mariadb/mariadb.pid

!includedir /etc/my.cnf.d

6、设置my.cnf相关的目录的权限

# mkdir -p /mnt/logs/mysql/

# chown -R mysql:mysql /mnt/logs/mysql/.

# touch /mnt/logs/mysql/error.log

# chmod -R 777 /mnt/logs/mysql/error.log

# touch /mnt/logs/mysql/slow.log

# chmod -R 777 /mnt/logs/mysql/slow.log

7、为mysql配置环境变量

vim /etc/profile // 打开profile文件,在文件末尾添加下面三行

export MYSQL_HOME

MYSQL_HOME=/mnt/local/mysql

export PATH=$PATH:$MYSQL_HOME/lib:$MYSQL_HOME/bin

执行:source /etc/profile 

创建软连接

# ln -s /mnt/local/mysql/bin/mysql /usr/bin/mysql

Tip:删除软连接:rm -rf mysql,不要带/,否则会将源文件删除掉

 

8、设置为开机自启动项。

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

# chmod +x /etc/init.d/mysql //添加可执行权限。

# chkconfig --add mysql // 注册启动服务

输入chkconfig --list //查看是否添加成功

启动:service mysql start

停止:service mysql stop

重启:service mysql restart

说明:basedir如果指定不是/usr/local/mysql目录则启动mysql时可能会报(在本次安装mysql8.0.18地未遇到,在之前遇到过):

# service mysql start

/etc/init.d/mysql: line 239: my_print_defaults: command not found

/etc/init.d/mysql: line 259: cd: /usr/local/mysql: No such file or directory

Starting MySQLCouldn't find MySQL server (/usr/local/mysql/[FAILED]ld_safe)

解决办法:

由上面可知mysql的tar.gz安装包的默认安装目录为/usr/local/mysql, 这时候我们需要修改/support-files/mysql.server文件的basedir和datadir目录路径为我们环境所在的mysql的basedir和datadir路径, 如下:

# vim /etc/init.d/mysql

--------------------------

...

basedir=/mnt/local/mysql

datadir=/mnt/data/mysql

...

--------------------------

mysql -u root -p //登录进入mysql,然后提示输入密码并让修改系统自动生成的密码

mysql8设置用户新密码方式

> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'your password';

> FLUSH PRIVILEGES

设置允许root远程访问(慎用)

> use mysql

mysql> select host,user from user;

mysql> update user set host='%' where host = 'localhost';

mysql> FLUSH PRIVILEGES;

 

你可能感兴趣的:(MySQL)