CentOS7.6 installation MySQL8.0 (Photo detailed)

table of Contents

I. Before You Begin

 Second, install MySQL

Third, set up remote login 

 Fourth, the installation problem solving

Fifth, set up MySQL boot from Kai


I. Before You Begin

1, the official website to download MySQL installation package (note the downloaded installation package type)

 2, to see if the installation mariadb

 # rpm -qa | grep mariadb

3, uninstall mariadb

# rpm -e --nodeps mariadb-libs-5.5.60-1.el7_5.x86_64

4, the installation dependencies MySQL libaio

# yum install libaio

 

5, create a MySQL installation directory and data storage directory, and authorized

# mkdir /usr/local/mysql

# mkdir /usr/local/mysql/mysqldb

# chmod -R 777 /usr/local/mysql

# chmod -R 777 /usr/local/mysql/mysqldb/

6, create a group MySQL: Creating a MySQL user and password.

 # useradd mysql
# passwd mysql

7, mysql directory permissions granted to mysql and mysql user group

 # chown -R mysql:mysql /usr/local/mysql

8, upload and extract the installation package (ftp uploading tools such as through)

# cd /usr/local/mysql

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

After extracting follows:

9, create a MySQL installation initial configuration file my.cnf

# We /etc/my.cnf

[mysqld]
# 设置3306端口
port=3306
# 设置mysql的安装目录
basedir=/usr/local/mysql/mysql-8.0.16-el7-x86_64
# 设置mysql数据库的数据的存放目录
datadir=/usr/local/mysql/mysqldb
# 允许最大连接数
max_connections=10000
# 允许连接失败的次数。这是为了防止有人从该主机试图攻击数据库系统
max_connect_errors=10
# 服务端使用的字符集默认为UTF8
character-set-server=utf8
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
# 默认使用“mysql_native_password”插件认证
default_authentication_plugin=mysql_native_password
[mysql]
# 设置mysql客户端默认字符集
default-character-set=utf8
[client]
# 设置mysql客户端连接服务端时默认使用的端口
port=3306
default-character-set=utf8
 

 二、安装MySQL

10、安装MySQL

进入MySQL安装目录:

# cd /usr/local/mysql/mysql-8.0.16-el7-x86_64/bin/

安装MySQL,并记住随机密码

# ./mysqld --initialize --console

11、启动MySQL服务

# cd ..
# cd support-files/
# ./mysql.server start

 注意:如果启动有问题,请看文章最后的安装问题!

12、将MySQL加入系统进程中

#  cp mysql.server /etc/init.d/mysqld

重启MySQL服务:

# service mysqld restart

13、修改登录密码

# cd ..

# cd bin/

# ./mysql -u root -p

修改密码:

 mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'centos_data';

三、设置远程登录 

14、设置允许远程登录

mysql> use mysql;

mysql> update user set user.Host='%' where user.User='root';

mysql> flush privileges;

详细设置请参考另一篇文章:https://blog.csdn.net/dbdd_cf/article/details/93734336 

退出MySQL:

mysql> quit;

重启MySQL服务:

 # service mysqld restart

 

至此MySQL安装完成!

 四、安装问题解决

  •  安装问题:

1、启动MySQL服务问题:

(1)启动MySQL服务时报 my_print_defaults:未找到命令错误。

解决方法:修改 /etc/my.cnf 中的 MySQL的安装目录,如图:

(2)启动MySQL服务时报 updating PID file 错误。

 解决方法:在安装目录下重新授权,然后再启动MySQL!

# chmod -R 777 /usr/local/mysql/mysql-8.0.16-el7-x86_64

# chmod -R 777 /usr/local//mysql/mysqldb

 2、任意目录登录MySQL问题:

原因:

这是由于系统默认会查找 /usr/bin 下的命令,如果这个目录下没有这个命令,就会报 未找到命令。

解决方法:创建一个软连接到 /usr/bin。

 # ln -s /usr/local/mysql/mysql-8.0.16-el7-x86_64/bin/mysql /usr/bin

五、设置MySQL开机自启

1、先将MySQL加入系统进程(第10步已做)

# cp /usr/local/mysql/mysql-8.0.16-el7-x86_64/support-files/mysql.server  /etc/init.d/mysqld

赋予可执行权限:# chmod +x /etc/init.d/mysqld

添加为服务:# chkconfig --add mysqld

查看服务列表:# chkconfig --list

 注:3、4、5的状态为开或者on,则表示成功。如果是管或者off,则需要执行:# chkconfig --level 345 mysqld on

最后重启服务器:reboot

再次查看服务列表或者查看3306端口:

启动成功! 


欢迎进群:747509472 交流学习,感谢指正!

 

Guess you like

Origin www.cnblogs.com/dbdd/p/12159439.html