mysql安装和简单命令

 

mysql安装包及其依赖下载地址https://downloads.mysql.com/archives/community/

1、下载MySQL的安装文件
安装MySQL需要下面两个文件

  rpm -ivh mysql-community-server-5.7.28-1.el7.x86_64.rpm
  rpm -ivh mysql-community-client-5.7.28-1.el7.x86_64.rpm

另外还需两个依赖包

mysql-community-libs-5.7.28-1.el7.x86_64.rpm
mysql-community-common-5.7.28-1.el7.x86_64.rpm

下载方式地址如下(需注册登录oracle账户):

wget https://downloads.mysql.com/archives/get/p/23/file/mysql-community-common-5.7.28-1.el7.x86_64.rpm
wget https://downloads.mysql.com/archives/get/p/23/file/mysql-community-libs-5.7.28-1.el7.x86_64.rpm
wget https://downloads.mysql.com/archives/get/p/23/file/mysql-community-client-5.7.28-1.el7.x86_64.rpm
wget https://downloads.mysql.com/archives/get/p/23/file/mysql-community-server-5.7.28-1.el7.x86_64.rpm 

2、安装mysql,执行如下命令依次安装,

[root@realhost ~]# rpm -ivh mysql-community-common-5.7.28-1.el7.x86_64.rpm
warning: mysql-community-common-5.7.28-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-common-5.7.28-1.e################################# [100%]

[root@realhost ~]# rpm -ivh mysql-community-libs-5.7.28-1.el7.x86_64.rpm
warning: mysql-community-libs-5.7.28-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-libs-5.7.28-1.el7################################# [100%]
[root@realhost ~]# rpm -ivh mysql-community-client-5.7.28-1.el7.x86_64.rpm
warning: mysql-community-client-5.7.28-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-client-5.7.28-1.e################################# [100%]
[root@realhost ~]# rpm -ivh mysql-community-server-5.7.28-1.el7.x86_64.rpm
warning: mysql-community-server-5.7.28-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-server-5.7.28-1.e################################# [100%]
[root@realhost ~]# mysql --version
mysql  Ver 14.14 Distrib 5.7.28, for Linux (x86_64) using  EditLine wrapper


3、修改mysql默认密码

修改mysql配置文件

vim /etc/my.cnf

添加skip-grant-tables=1,取消数据库鉴权wq:保存退出   (修改完密码之后需要删除)

skip-grant-tables=1

重启mysqld服务

[root@realhost ~]# systemctl restart mysqld

登录数据库执行如下命令修改密码

[root@realhost ~]# vim /etc/my.cnf
[root@realhost ~]# systemctl restart mysqld
[root@realhost ~]# mysql -uroot
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.28 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> use mysql              //进入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> update user set password = password('123456') where user='root';  
ERROR 1054 (42S22): Unknown column 'password' in 'field list'     //mysql5.7版本以前使用此命令修改密码,5.7版本以后请使用下面命令
mysql> update user set authentication_string = password('123456') where user='root';
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 1          //此处修改root的密码是123456

mysql> \q
Bye

删除之前的配置文件重启mysqld服务使用修改后的密码登录

[root@realhost ~]# vim /etc/my.cnf
[root@realhost ~]# systemctl restart mysqld
[root@realhost ~]# mysql -uroot                //取消配置文件后无密码已经登录不上数据库了。
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
[root@realhost ~]# mysql -uroot -p123456           //使用密码123456登录成功,验证修改成功
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 3
Server version: 5.7.28

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密码修改的三种方式:

[root@realhost ~]# mysqladmin -uroot -p123456 password "新密码"   //123456是旧密码
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.
mysql>  set password for root@localhost=password("新密码");
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> alter user root@localhost identified by '新密码';
Query OK, 0 rows affected (0.00 sec)

修改密码报错处理

mysql>  set password for root@localhost=password("newpassword");
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements

密码不满足策略要求,查看密码策略

mysql> SHOW VARIABLES LIKE 'validate_password%';
+--------------------------------------+--------+
| Variable_name                        | Value  |
+--------------------------------------+--------+
| validate_password_check_user_name    | OFF    |
| validate_password_dictionary_file    |        |
| validate_password_length             | 8      |
| validate_password_mixed_case_count   | 1      |
| validate_password_number_count       | 1      |
| validate_password_policy             | MEDIUM |
| validate_password_special_char_count | 1      |
+--------------------------------------+--------+

密码策略是MEDIUM故密码需要包含 数字、小写字母、大写字母 、特殊字符、且长度至少8位

可以将密码策略改为0/LOW,就可以正常修改了。

mysql>   set password for root@localhost=password("12345678");
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
mysql> set global validate_password_policy=0
    -> ;
Query OK, 0 rows affected (0.00 sec)

mysql> set password for root@localhost=password("12345678");
Query OK, 0 rows affected, 1 warning (0.00 sec)

各项值说明

validate_password_policy:密码安全策略,默认MEDIUM策略

策略检查规则
0 or LOWLength
1 or MEDIUMLength; numeric, lowercase/uppercase, and special characters
2 or STRONGLength; numeric, lowercase/uppercase, and special characters; dictionary file
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值