EverKB

Knowledge Base Ever

在CentOS7上安装MySQL8及用户权限配置

2019-11-15 11:37:53

标签: CentOS, MySQL, CentOS7, MySQL8, mysql_native_password, caching_sha2_password,INDENTIFIED BY, 安装MySQL, 安装MySQL8, MySQL权限, MySQL8权限

vim编辑/etc/yum.repos.d/mysql-community.repo文件,保存以下内容

[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

安装MySQL8

yum -y install mysql-community-server

使用systemd管理MySQL

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

内容如下,保存文件:

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

设置MySQL服务器开机自动运行,并启动服务

systemctl daemon-reload
systemctl enable mysqld
systemctl start mysqld

查看root用户初始密码,并登录后修改密码

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'

授权root用户远程访问

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

创建新用户,并授权访问

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

设置密码验证方式

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;

或者通过修改配置文件:/etc/my.cnf中的mysql_native_password

[mysqld]
default_authentication_plugin=mysql_native_password

标签

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