EverKB

Knowledge Base Ever

Install MySQL8 and user rights configuration on CentOS7

2019-11-15 11:37:53

label: CentOS, MySQL, CentOS7, MySQL8, mysql_native_password, caching_sha2_password,INDENTIFIED BY, Install MySQL, install MySQL8, MySQL permissions, MySQL8 permissions

Vim edit the /etc/yum.repos.d/mysql-community.repo file and save the following

[mysql80-community]
name=MySQL 8.0 Community Server
baseurl=http://repo.mysql.com/yum/mysql-8.0-community/el/7/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

Install MySQL8

yum -y install mysql-community-server

Manage MySQL with systemd

mkdir /etc/systemd/system/mysqld.service.d
cd /etc/systemd/system/mysqld.service.d
vim override.conf

The content is as follows, save the file:

[Service]
PIDFile=/var/run/mysqld/mysqld-custom.pid
ExecStart=
ExecStart=/usr/sbin/mysqld --pid-file=/var/run/mysqld/mysqld-custom.pid $MYSQLD_OPTS

Set the MySQL server to run automatically and start the service.

systemctl daemon-reload
systemctl enable mysqld
systemctl start mysqld

Check the initial password of the root user and change the password after logging in.

Cat /var/log/mysqld.log

[root@carbon ~]# mysql -u root -p
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

Mysql> USE mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
Mysql> SELECT user, host FROM user;
+------------------+-----------+
| user | host |
+------------------+-----------+
| mysql.infoschema | localhost |
| mysql.session | localhost |
| mysql.sys | localhost |
| root | localhost |
+------------------+-----------+
5 rows in set (0.00 sec)

Mysql> SET global validate_password.policy=0;
Mysql> ALTER USER 'root'@'%' IDENTIFIED BY 'PASSWORD'

Authorize root user remote access

CREATE USER 'root'@'%' INDENTIFIED BY 'admin';
ALTER USER 'root'@'%' IDENTIFIED BY 'admin';
FLUSH PRIVILEGES;

Create new users and authorize access

CREATE DATABASE test;
CREATE USER 'mysql'@'%' INDENTIFIED BY 'admin';
CREATE USER 'mysql'@'localhost' INDENTIFIED BY 'admin';
FLUSH PRIVILEGES;

Set password verification method

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'admin';
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'admin';
ALTER USER 'mysql'@'localhost' IDENTIFIED WITH mysql_native_password BY 'admin';
ALTER USER 'mysql'@'%' IDENTIFIED WITH mysql_native_password BY 'admin';
FLUSH PRIVILEGES;

Or by modifying the configuration file: mysql_native_password in /etc/my.cnf

[mysqld]
default_authentication_plugin=mysql_native_password

label

CentOS7 CentOS PHP Linux Python3 Python MySQL MariaDB YUM JavaScript CSS Redis MySQL8 caching_sha2_password HTML mysql_native_password PHP7 jQuery PHP5.5 src Apache du nginx Shadowsocks-Python V2Ray cURL hide MariaDB10.4 PostgreSQL sub folder availability eth0 Install MongoDB pdo_sqlsrv SOCKS5 Web Server date mssql-tools register_shutdown_function Symfony File Upload JetBrain php-fpm sqlsrv Zend Framework ADDDATE DevExpress network interface Shadowsocks-Libev unixODBC-devel height Port 80 string Aura error_get_last password policy requirements SOCKS Web Development data INDENTIFIED BY msodbcsql Redis5 SVN Fedora Media Writer jemalloc SQLAlchemy absolute Deepin mysqlclient Shadowsocks toggle convert FuelPHP margin PHPUnit Framework ss5.passwd at-symbol Error Control Operator password SOCKET vps daemon process IIS MongoDB4 sudoers center Fatal Errors Phalcon SQL Server 2017 WiFi .htaccess DATE_SUB set_error_handler TestCase Compiling PHP frequency conflict PHPUnit ss5.conf apr Elasticsearch7.3 particles.js Slim Vincent Garreau daemon HTTP MongoDB Sudo Failed to build these modules: _uuid ip command pg_bha.conf SQL Server width DATE_ADD MySQL-python scrollbar Tcp BBR Compiling Apache Frameworks libpython3.7m.so.1.0 PHPStorm ss5-3.8.9 Apache2.4 Elasticsearch NodeJs show VIM CURLOPT_POSTFIELDS Minimal ISO substr Bluetooth Failed to build these modules: _ctypes INTERVAL PECL SQL Date Funcitons Wi-Fi date sub root Tag Cloud CodeIgniter font-size Laravel ss5 apache httpd dual network interfaces node.js ShadowsocksR vertical-align CURLFille horiz-align mb_substr PyCharm SUBDATE BarManager exec IntelliJIDEA PEAR SOCKS5 Proxy Server WebStorm date add remi Tag Chrome find