[Advanced MySQL]: Install MySQL8 on Linux (centos8) system

【statement】

table of Contents

Download the MySQL installation package from the official website

Install MySQL

Uninstall mysql pre-installed in centos

Install dependencies 

Install the RPM package (note the installation order)

Check if the installation is successful

Initialize mysql

/var/lib/mysql directory permission authorization

Start mysql service

View the initial randomly generated root password

Security Settings

Set the root user's localhost to% (used to connect to Navicat)

Stop, restart and view the mysql service

mysql related installation directory files

Need to close the firewall or open port 3306

Download the MySQL installation package from the official website

  • Select version

  • Download the corresponding installation package

  • Transfer the downloaded file to /usr/local/Mysql8

Install MySQL

Uninstall mysql pre-installed in centos

rpm -qa | grep -i mysql

  • If installed, uninstall
rpm -e 安装的mysql --nodeps

Install dependencies 

yum -y install libaio.so.1 libgcc_s.so.1 libstdc++.so.6 libncurses.so.5 --setopt=protected_multilib=false

Install the RPM package (note the installation order)

rpm -ivh 安装包

Check if the installation is successful

ps -ef | grep mysql

mysqladmin --version

Initialize mysql

  • Create data file directory and mysql system database to generate random root password
mysqld --initialize

/var/lib/mysql directory permission authorization

chown -R mysql:mysql /var/lib/mysql/

Start mysql service

  • start up
systemctl start mysqld 

  • View mysql service
ps -ef | grep mysql

View the initial randomly generated root password

cat /var/log/mysqld.log | grep password

Security Settings

mysql_secure_installation

 

  • 1. Whether to set the authentication password component, I did not check what it is, because it is not used, I directly select No;
  • 2. Whether to change the root password, input y will reset the new password, we have changed the password, select No;
  • 3. Whether to delete anonymous users, the suggestion is to delete, choose y;
  • 4. Whether to prohibit root remote login, it is recommended to prohibit it, choose y; (wait, why prohibit it, don't we want to log in remotely? Yes, the configuration of Navicat login will be introduced later, temporarily set it to y for security considerations )
  • 5. Whether to delete the test database, select y;
  • 6. Whether to reload the permission table, select y.
  • [Note: Reference  Centos8 installation mysql8.0  (Author: feng_shede )

After the security configuration, log in to the database and type the command:

mysql -uroot -p

Set the root user's localhost to% (used to connect to Navicat)

use mysql

select user,host from user;

update user set host = '%' where user = 'root';

flush privileges;

ALTER USER 'root'@'%' IDENTIFIED BY '123456' PASSWORD EXPIRE NEVER;   -- 更改加密方式

ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456';   -- 更新用户密码

flush privileges;  -- 刷新权限

Stop, restart and view the mysql service

systemctl stop mysqld -- 停止服务

systemctl restart mysqld -- 重启服务

systemctl status mysqld -- 查看服务

mysql related installation directory files

/usr/share/mysql   //配置文件目录

/var/lib/mysql     //数据库文件存放目录

/etc/my.cnf        //mysql的启动配置文件

mysqld            //是后台守护进程,即mysql daemon

mysql             //是客户端命令行

Need to close the firewall or open port 3306

service iptables stop #暂时关闭

chkconfig iptables off #设置成开启不自启(这个命令没有测试,可以自己试一下,centos8应该是不支持chkconfig 命令了)

/sbin/iptables -I INPUT -p tcp --dport 3306 -j ACCEPT #开启3306端口

/etc/rc.d/init.d/iptables save #保存配置

/etc/rc.d/init.d/iptables restart #重启服务

 

Guess you like

Origin blog.csdn.net/baidu_41388533/article/details/108931490