发布时间:2026-07-21阅读(1)
[root@localhost ~]# wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
[root@localhost ~]# yum -y install mysql57-community-release-el7-10.noarch.rpm[root@localhost ~]# yum -y install mysql-community-server[root@localhost ~]# service mysqld status[root@localhost ~]# service mysqld start[root@localhost ~]# service mysqld stop

[root@localhost ~]# grep "password" /var/log/mysqld.log[root@localhost ~]# use mysql
mysql> use mysqlmysql> show variables like validate_password%

mysql> set global validate_password_policy=0;mysql> set global validate_password_length=6;
方式一: set 并设置密码永不过期mysql> set password=password(123456); # set设置mysql> alter user root@localhost password expire never;mysql> flush privileges;mysql> exit; 方式二: update用户密码mysql> update user set password=password("123456") where user=root; # update更新mysql> flush privileges;mysql> exit;
首先,你必须有linux的系统root权限,可以 sudo su然后,使用Mysql的安全模式进入service mysqld stop(要先将mysqld添加为系统服务)mysqld_safe --skip-grant-tables &或者mysqld_safe --defaults-file=/etc/my.cnf --skip-grant-tables & 接着重置密码:# mysql #5.6及以前mysql> UPDATE mysql.user SET password=password(123456) WHERE user=root; # 5.7;mysql.user表authentication_string字段替换了password字段;mysql> UPDATE mysql.user SET authentication_string=password(123456) WHERE user=root; mysql> flush privileges;mysql> exit;
1. 查看端口,默认是3306mysql> show global variables like port;2. 修改端口,进入my.cnf文件,添加port=2206 ,然后重启服务[root@localhost ~] vi /etc/my.cnf[root@localhost ~] /etc/init.d/mysqld restart
create user tong identified by 123; create user tong@localhost identified by 123; 只能本地登录 mysql> create user tong@192.168.206.0/255.255.255.0 identfied by 123; 192.168.206.0/24 #网段 mysql> create user tong@192.168.206.10 identfied by 123; 只允许192.168.206.10该ip登录 create user tom@% identified by 123; 所有能连接主机
grant select on mydb.* to tong@localhost; #授权查看的权限 show grants for tong\G *************************** 1. row *************************** Grants for tong@%: GRANT USAGE ON *.* TO tong@% IDENTIFIED BY PASSWORD *23AE809DDACAF96AF0FD78ED04B6A265E05AA257 *************************** 2. row *************************** Grants for tong@%: GRANT SELECT ON `mydb`.* TO tong@%远程主机授权grant all on mydb.* to tom@192.168.206.10 identified by 123; grant all on mydb.* to tom@% identified by 123;授权selecet和insert权限grant select,insert on mydb.* to jerry@localhost identified by 123;授权某个特定的表访问权限grant select,insert on mydb.test to tom@localhost identified by 123;
drop user tong;drop user tong@192.168.206.10;revoke 权限 on 库.表 from 用户@主机;revoke select on mydb.* from tonglocalhost;
Copyright © 2024 有趣生活 All Rights Reserve吉ICP备19000289号-5 TXT地图HTML地图XML地图