Yum安装MySQL8.0

DevOps MySQL评论6,881字数 3890阅读12分58秒阅读模式

安装mysql

Yum安装MySQL8.0

安装前,我们可以检测系统是否自带安装 MySQL

rpm -qa | grep mysql

普通删除模式

 rpm -e mysql

强制删除

rpm -e --nodeps mysql

安装rpm包

wget https://repo.mysql.com//mysql80-community-release-el7-1.noarch.rpm
rpm -ivh mysql80-community-release-el7-1.noarch.rpm
rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
yum install mysql-server -y

启动mysql

systemctl start mysqld
systemctl enable mysqld

默认文件及目录路径

客户端程序和脚本:/usr/bin 
配置文件:/etc/my.cnf 
数据目录路径:/var/lib/mysql 
错误日志文件:/var/log/mysqld.log 
PID文件:/var/run/mysql/mysqld.pid 
Socket文件:/var/lib/mysql/mysql.sock 
手册页:/usr/share/man 
包含(头)文件:/usr/include/mysql 
lib库文件:/usr/lib/mysql 
其他支持文件(例如,错误消息和字符集文件):/usr/share/mysql 
服务启动脚本:/usr/lib/systemd/system/mysqld.service

MySQL安全设置

mysql修改密码

[root@i-zn91u22o ~]# grep 'temporary password' /var/log/mysqld.log 
2022-02-28T07:44:31.500768Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: +s>3)K)*jCBs
[root@i-zn91u22o ~]# 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: 
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) : y
Success.

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
Success.

All done!

远程访问设置

[root@i-zn91u22o ~]# mysql -uroot -pddfsdf!
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 16
Server version: 8.0.28 MySQL Community Server - GPL

Copyright (c) 2000, 2022, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

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> CREATE USER 'lucky'@'%' IDENTIFIED WITH mysql_native_password BY 'M*rdS9kyT8WqG%apY#h'; 
Query OK, 0 rows affected (0.01 sec)

mysql> GRANT ALL PRIVILEGES ON *.* TO 'lucky'@'%' WITH GRANT OPTION; 
Query OK, 0 rows affected (0.01 sec)

mysql> FLUSH PRIVILEGES; 
Query OK, 0 rows affected (0.00 sec)

查看远程用户信息

mysql> use mysql; 
Database changed
mysql> select user,host from user; 
+------------------+-----------+
| user             | host      |
+------------------+-----------+
| lucky            | %         |
| mysql.infoschema | localhost |
| mysql.session    | localhost |
| mysql.sys        | localhost |
| root             | localhost |
+------------------+-----------+
5 rows in set (0.00 sec)

验证远程账号

[root@i-zn91u22o ~]# mysql -ulucky -pM*rdS9kyT8WqG%apY#h
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.28 MySQL Community Server - GPL

Copyright (c) 2000, 2022, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)

 

继续阅读
MySQL最后更新:2022-4-29
DevOps
  • 本文由 发表于 2022年2月28日 15:21:13
  • 除非特殊声明,本站文章均为原创,转载请务必保留本文链接
  • MySQL
部署MySQL服务 MySQL

部署MySQL服务

设置 Repo [root@hecs-x-large-2-linux-20200321161149 ~]# yum -y localinstall http://mirrors.ustc.edu.c...
评论  0  访客  0

发表评论