centos7系统自带mariadb数据库,先卸载再安装mysql,防止有冲突。
如果/etc下有my.cnf也卸载掉
- 查询是否有安装的mariadb文件
rpm -qa | grep mariadb mariadb-libs-5.5.52-1.el7.x86_64
- 使用-nodeps 不考虑依赖,强制卸载
rpm -e --nodeps mariadb-libs-5.5.52-1.el7.x86_64
- 配置Mysql 8.0安装源:
sudo rpm -Uvh https://dev.mysql.com/get/mysql80-community-release-el7-1.noarch.rpm
- 安装Mysql 8.0
sudo yum --enablere
- 启动Mysql服务
sudo service mysqld start
结果如下,表示成功
Redirecting to /bin/systemctl status mysqld.service
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since 二 2019-02-19 16:56:11 CST; 4min 1s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 22953 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
Main PID: 23048 (mysqld)
Status: "SERVER_OPERATING"
CGroup: /system.slice/mysqld.service
└─23048 /usr/sbin/mysqld
2月 19 16:56:02 localhost.localdomain systemd[1]: Starting MySQL Server...
2月 19 16:56:11 localhost.localdomain systemd[1]: Started MySQL Server.
- 查看root用户临时密码
grep "A temporary password" /var/log/mysqld.log
2019-02-19T08:56:07.061965Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: ;q46,&W.v>Ty
如图中q46,&W.v>Ty就是密码
- 配置Mysql安全策略 设置的密码为#######
mysql_secure_installation
mysql_secure_installation
Securing the MySQL server deployment.
Enter password for user root:
The existing password for the user account root has expired. Please set a new password.
New password:
Re-enter new password:
... Failed! Error: Your password does not satisfy the current policy requirements
New password:
Re-enter new password:
The 'validate_password' component is installed on the server.
The subsequent steps will run with the existing configuration
of the component.
Using existing password for root.
Estimated strength of the password: 100
Change the password for root ? ((Press y|Y for Yes, any other key for No) : y
New password:
Re-enter new password:
Estimated strength of the password: 100
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : no
New password:
Re-enter new password:
Estimated strength of the password: 100
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.
Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
Success.
Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : n
... skipping.
By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
- Dropping test database...
Success.
- Removing privileges on test database...
Success.
Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
- 配置远程访问
- 登录mysql控制台: mysql -uroot –p#######
mysql -uroot -p#######
2、创建新的远程用户:CREATE USER 'test'@'%' IDENTIFIED BY ' #######';
3、授权给远程用户:GRANT ALL ON *.* TO 'test'@'%';(ALL表示授予所有权限、*.*表示所有数据库中的所有表、%表示任意IP可以远程连接)
其他权限:ALTER、ALTER ROUTINE、CREATE、CREATE ROUTINE、CREATE TABLESPACE、CREATE TEMPORARY TABLES、CREATE USER、CREATE VIEW、DELETE、DROP、EVENT、EXECUTE、FILE、GRANT OPTION、INDEX、INSERT、LOCK TABLES、PROCESS、PROXY、REFERENCES、RELOAD、REPLICATION CLIENT、REPLICATION SLAVE、SELECT、SHOW DATABASES、SHOW VIEW、SHUTDOWN、SUPER、TRIGGER、UPDATE、USAGE。