【centos】rpm安装MySQL

第一步、前往mysql官网下载所需的版本

  Mysql5.7的rpm包下载地址为https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.26-1.el7.x86_64.rpm-bundle.tar

  下载完成后就上传的

wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.26-1.el7.x86_64.rpm-bundle.tar

CentOS系统上。

第二步、解压安装

[root@manager ~]# mkdir Mysql  //创建一个专门的Mysql目录
[root@manager ~]# tar xf mysql-5.7.16-1.el7.x86_64.rpm-bundle.tar -C Mysql/  //将解压的文件放到Mysql目录下
[root@manager ~]# yum -y install make gcc-c++ cmake bison-devel ncurses-devel libaio libaio-devel net-tools  //安装依赖包

由于CentOS7开始自带的数据库是mariadb,所以需要卸载系统中的mariadb组件,才能安装mysql的组件

[root@manager mysql]# rpm -qa|grep mariadb
mariadb-libs-5.5.65-1.el7.x86_64
mariadb-5.5.65-1.el7.x86_64
[root@manager mysql]# yum -y remove mariadb-libs.x86_64 

  现在开始安装mysql,由于依赖关系,所以顺序是固定的。

[root@manager mysql]# rpm -ivh mysql-community-common-5.7.26-1.el7.x86_64.rpm
warning: mysql-community-common-5.7.26-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-common-5.7.26-1.e################################# [100%]
[root@manager mysql]# rpm -ivh mysql-community-libs-5.7.26-1.el7.x86_64.rpm 
warning: mysql-community-libs-5.7.26-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-libs-5.7.26-1.el7################################# [100%]
[root@manager mysql]# rpm -ivh mysql-community-libs-compat-5.7.26-1.el7.x86_64.rpm 
warning: mysql-community-libs-compat-5.7.26-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-libs-compat-5.7.2################################# [100%]
[root@manager mysql]# rpm -ivh mysql-community-client-5.7.26-1.el7.x86_64.rpm 
warning: mysql-community-client-5.7.26-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-client-5.7.26-1.e################################# [100%]
[root@manager mysql]# rpm -ivh mysql-community-server-5.7.26-1.el7.x86_64.rpm 
warning: mysql-community-server-5.7.26-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-server-5.7.26-1.e################################# [100%]

  第三步、启动mysql并设置开机自启

[root@manager mysql]# systemctl start mysqld
[root@manager mysql]# systemctl enable mysqld
[root@manager mysql]# systemctl status mysqld
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since Fri 2020-08-28 12:38:45 CST; 30s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
 Main PID: 11522 (mysqld)
   CGroup: /system.slice/mysqld.service
           └─11522 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid

Aug 28 12:38:34 manager systemd[1]: Starting MySQL Server...
Aug 28 12:38:45 manager systemd[1]: Started MySQL Server.

 

第四步、获取mysql临时密码,设置mysql的root用户密码

[root@manager mysql]# grep "password" /var/log/mysqld.log   //前往日志文件查找临时密码
2020-08-28T04:38:42.576429Z 1 [Note] A temporary password is generated for root@localhost: AXp(y:m.1p0M
[root@manager mysql]# mysql -uroot -p"AXp(y:m.1p0M"
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 2
Server version: 5.7.26

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

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> alter user 'root'@'localhost' identified by 'DBapp@2020';   //修改密码
Query OK, 0 rows affected (0.00 sec)

mysql> exit
Bye

 修改密码出来使用“alter user 'root'@'localhost' identified by 'root1234ABCD!@#$';”,也可以使用“set password for root@localhost=password('root1234ABCD!@#$');”

第五步、测试

  由于有特殊符号,必须用引号包裹密码

[root@manager mysql]# mysql -uroot -p 
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.26 MySQL Community Server (GPL)

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

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> 

扩展:如果想要设置简单密码概如何操作?

  有两种方法,一种在mysql里使用命令修改,一种直接修改配置文件。

  在mysql里使用命令修改的办法:

mysql> select @@validate_password_policy;  //这个参数是密码复杂程度
+----------------------------+
| @@validate_password_policy |
+----------------------------+
| MEDIUM                     |
+----------------------------+
1 row in set (0.02 sec)
mysql> select @@validate_password_length;  //这个参数是密码长度
+----------------------------+
| @@validate_password_length |
+----------------------------+
|                          8 |
+----------------------------+
1 row in set (0.00 sec)
mysql> set global validate_password_policy=0;  //global全局的
Query OK, 0 rows affected (0.02 sec)
mysql> set global validate_password_length=1;
Query OK, 0 rows affected (0.00 sec)
mysql> set password for root@localhost=password('123');
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
mysql> set password for root@localhost = password('1234');  //设置密码
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> flush privileges;  //刷新
Query OK, 0 rows affected (0.00 sec)
mysql> exit  //退出
Bye

 说明:1.validate_password_policy复杂度级别:0表示密码达到长度即可;1表示密码需达到长度,还需有数字、大小写字母(可以单一可以混合)以及特殊字符;2表示密码需达到长度,还需数字、大小写字母(可以单一可以混合)以及特殊字符字典文件。MEDIUM是中等,也就是1。

    2.validate_password_length其实是一个动态的值,它的最小值等于validate_password_number_count+validate_password_special_char_count+(2*validate_password_mixed_case_count),而这三个参数分别对应密码中数字、特殊字符、大小写字母的最小数量。我操作时设置了validate_password_length=1,实际再次读取validate_password_length的值是4。

 建议:/etc/my.cnf中将默认字符集设置为utf8,即添加一行character_set_server=utf8,然后重启mysqld

你可能感兴趣的:(centos7,数据库,mysql,centos,linux)