怎么修改mysql mysql修改root密码mac的最新相关信息

拒绝访问 |
| 百度云加速
请打开cookies.
此网站 () 的管理员禁止了您的访问。原因是您的访问包含了非浏览器特征(38ad88-ua98).
重新安装浏览器,或使用别的浏览器用户名:yangji008
文章数:1089
评论数:26
访问量:805338
注册日期:
阅读量:1297
阅读量:3317
阅读量:443787
阅读量:1129629
51CTO推荐博文
我这里是通过mysql官方的yum源来安装的mysql-community-server ,当前版本是MySQL 5.7.12 。wget&
rpm&-ivh&&mysql57-community-release-el6-8.noarch.rpm
yum&install&mysql-community-server
service&mysqld&start第一次启动后会有个初始化的过程,会产生root账户的随机密码。为了加强安全性,MySQL5.7为root用户随机生成了一个密码,在error_log中,关于error_log的位置,如果安装的是RPM包,则默认是 /var/log/mysqld.log 。找到生成的随机密码mysql&-u&root&-p'zXMgg%#L3=;1'
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&4
Server&version:&5.7.12
Copyright&(c)&,&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
Type&''&or&'\h'&for&help.&Type&'\c'&to&clear&the&current&input&statement.
mysql&&show&
ERROR&1820&(HY000):&You&must&reset&your&password&using&ALTER&USER&statement&before&executing&this&statement.
mysql&&show&
ERROR&1820&(HY000):&You&must&reset&your&password&using&ALTER&USER&statement&before&executing&this&statement.登陆上过后,进行正常操作会受限,提示你必须修改密码后才能进行操作。好吧,根据提示修改密码:mysql&&SET&PASSWORD&=&PASSWORD('123456');&
ERROR&1819&(HY000):&Your&password&does&not&satisfy&the&current&policy&requirements
mysql&&SET&PASSWORD&=&PASSWORD("root");
ERROR&1819&(HY000):&Your&password&does&not&satisfy&the&current&policy&requirements但是提示根据当前密码策略,设置的密码不允许。查阅官方文档后发现有以下三种密码策略:PolicyTests Performed0&or&LOWLength1&or&MEDIUML numeric, lowercase/uppercase, and special characters2&or&STRONGL numeric, lowercase/uppercase, an dictionary file当前密码策略默认为1 也就是 MEDIUMmysql&root@localhost:(none)&&show&VARIABLES&like&"%password%"
+---------------------------------------+---------+
|&Variable_name&&&&&&&&&&&&&&&&&&&&&&&&&|&Value&&&|
|---------------------------------------+---------|
|&default_password_lifetime&&&&&&&&&&&&&|&0&&&&&&&|
|&disconnect_on_expired_password&&&&&&&&|&ON&&&&&&|
|&log_builtin_as_identified_by_password&|&OFF&&&&&|
|&mysql_native_password_proxy_users&&&&&|&OFF&&&&&|
|&old_passwords&&&&&&&&&&&&&&&&&&&&&&&&&|&0&&&&&&&|
|&report_password&&&&&&&&&&&&&&&&&&&&&&&|&&&&&&&&&|
|&sha256_password_proxy_users&&&&&&&&&&&|&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&&&&&&&|
+---------------------------------------+---------+
13&rows&in&set
Time:&0.030s所以你更改密码的策略是 数字 小写字母 大写字母 特殊字符&长度至少8位 。更改完密码就可以进行数据库的操作了。mysql&root@localhost:(none)&&show&DATABASES;
+--------------------+
|&Database&&&&&&&&&&&|
|--------------------|
|&information_schema&|
|&mysql&&&&&&&&&&&&&&|
|&performance_schema&|
|&sys&&&&&&&&&&&&&&&&|
+--------------------+
4&rows&in&set
Time:&0.009s接下来修改默认密码策略(当然实际环境是不推荐修改为更低安全策略的)mysql&root@localhost:(none)&&set&global&validate_password_policy&=&0;
Query&OK,&0&rows&affected
Time:&0.003s现在设置完默认密码策略后,就只有 密码长度限制 了。默认为字符长度至少8位。其中:validate_password_number_count指定了密码中数据的长度,validate_password_special_char_count指定了密码中特殊字符的长度,validate_password_mixed_case_count指定了密码中大小字母的长度。这些参数,默认值均为1,所以validate_password_length最小值为4,如果你显性指定validate_password_length的值小于4,尽管不会报错,但validate_password_length的值将设为4。mysql&root@localhost:(none)&&set&global&validate_password_length&=&3;
Query&OK,&0&rows&affected
Time:&0.004s
mysql&root@localhost:(none)&&show&VARIABLES&&like&"validate_password_length"
+--------------------------+---------+
|&Variable_name&&&&&&&&&&&&|&&&Value&|
|--------------------------+---------|
|&validate_password_length&|&&&&&&&4&|
+--------------------------+---------+
1&row&in&set
Time:&0.010s如果修改了validate_password_number_count,validate_password_special_char_count,validate_password_mixed_case_count中任何一个值,则validate_password_length将进行动态修改。MySQL 5.7 默认安装了 validate_password 插件。 所以多了以上步骤。----------------------------------------------------------------------------通过my.cnf 配置文件设置密码策略的级别"/f"&28L,&987C&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&22,1&&&&&&&&&&All
#&For&advice&on&how&to&change&settings&please&see
#&/doc/refman/5.7/en/server-configuration-defaults.html
#&Remove&leading&#&and&set&to&the&amount&of&RAM&for&the&most&important&data
#&cache&in&MySQL.&Start&at&70%&of&total&RAM&for&dedicated&server,&else&10%.
#&innodb_buffer_pool_size&=&128M
#&Remove&leading&#&to&turn&on&a&very&important&data&integrity&option:&logging
#&changes&to&the&binary&log&between&backups.
#&Remove&leading&#&to&set&options&mainly&useful&for&reporting&servers.
#&The&server&defaults&are&faster&for&transactions&and&fast&SELECTs.
#&Adjust&sizes&as&needed,&experiment&to&find&the&optimal&values.
#&join_buffer_size&=&128M
#&sort_buffer_size&=&2M
#&read_rnd_buffer_size&=&2M
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
validate_password_policy=2最后一行 validate_password_policy 设置mysql启动的时候密码策略级别。 如果设置为3 ,那么需要指定字典文件。当然你也可以通过 my.cnf 配置文件关闭 validate_password 插件。只需要添加一行&validate_password&=&off编辑完配置文件后,重启mysqld服务即可生效。mysql&root@localhost:(none)&&show&VARIABLES&&like&"validate_password%"
+-----------------+---------+
|&Variable_name&&&|&Value&&&|
|-----------------+---------|
+-----------------+---------+
0&rows&in&set
Time:&0.008s关闭validate_password插件后,就没有了validate_password的一些参数变量。MySQL官方对于 validate_password 插件的使用介绍: --------------------------------------------------------------------------------MySQL 新版本默认监听在IPv6的地址族上。更改为监听IPv4地址族,修改 my.cnf 添加一行配置:bind-address&=&0.0.0.0重启mysqld &即可。本文出自 “” 博客,请务必保留此出处
了这篇文章
类别:┆阅读(0)┆评论(0)用户名:jalyzjs
文章数:268
访问量:113143
注册日期:
阅读量:1297
阅读量:3317
阅读量:443787
阅读量:1129629
51CTO推荐博文
一、创建mysql用户1 创建mysql数据库的管理用户& & /usr/bin/mysqladmin -uroot password mopgaming&&&&&&&&&&&&password前面一定不能--password,那是登录时需要输入的。如上命令回车即可。2.1 创建一般用户,并授权 GRANT&&&&工作中web服务器和mysql服务器不在同一台机器上,所以需要通过mysql的远程账户访问mysql语法:mysql& grant [权限1,权限2,..权限n] on [数据库名].[表名] to ['用户名']@['web服务器ip地址'] identified by ['密码'];& & grant all privileges on lottery.* to test@'%' identified by 'mopgaming';& && & 刷新系统权限& 授权test用户所有的权限,针对lottery数据库的所有表,test用户可以被任意ip登录,验证密码mopgmaing& & grant select,update,create on lottery.* to test@x.x.x.x identified by 'mopgaming';& && & 刷新系统权限& 授权test用户select,update,create权限,针对lottery数据库的所有表,并且只有指定ip(x.x.x.x)才能登录该用户,验证密码mopgaminga.数据库操作权限,14个权限:&&&&select,update,create,insert,delete,drop,index,alter,grant,references,reload,shutdown,process,file&&&&也可以被all privileges或者all代替,赋予所有权限。b.数据库表名称:&&&&可以被 *.* 代替,表示针对该服务器上所有数据库和表授权c.用户地址:&&&&可以是localhost,只针对本地用户,可以在本地登录mysql。也可以是ip,hostname主机名,域名,针对指定主机授权,创建的用户不能本地mysql -uxxxx -p形式登录。也可以是 &'%' ,表示授权任何主机连接,创建的用户不能本地mysql -uxxxx -p形式登录,‘10.10.86.%’指定给该网段的主机授权。d.验证密码:&&&&不能为空,否则创建失败,授权失败。2.2 创建用户方法二&#create user 'xxx(用户名)'@'用户地址(ip/localhost/域名/%)' identified by 'xxx(验证密码)'&#mysql -uroot -pmopgaming&&&&&cteate user test2@localhost identified by 'mopgaming';&&&&&& & 刷新系统权限该方法创建test2用户可以登上,但是没有授予mysql数据库任何操作权限,只能使用当前用户下生成的数据库。若再grant授权,则可以正常使用:&&&&&grant all privileges on *.* to test2@'%' identified by 'mopgaming';&&&&&& & 刷新系统权限二、撤销用户权限& revoke 权限 on 库名.表名 from 用户名@用户地址;& mysql -uroot -p&&&&&revoke select,insert on *.* from test2@'%'; &撤销test2用户select,insert权限。&&&&&revoke all&on test.* from test2@'%'; &撤销test2用户,针对test库的所有权限。 & & &&三、删除用户1 直接删除用户 drop user:将用户信息全部删掉,包括user表和mysql.db表中的权限信息。& mysql -uroot -p&&&&&drop user test1@'%';&&&&&&& &2 删除用户 delete from user:只会清除对应user创建的表,其他比如db表中信息还是存在。(通过 &select *还可以看到该用户对应的权限。如果delete删除该用户后,再最小权限创建一个同名的用户,那么会重用以前的权限。)&&& mysql -uroot -p&&&&&&&&&&delete from user where user=test1 and host='%';&&&&&&&四、修改指定用户密码& #mysql -uroot -p&& & update mysql.user set password=password('新密码') where user="test2" and host="%";& && 修改指定用户密码的命令必须按照此格式。五、远程访问测试授权的mysql用户&&&&#mysql -hx.x.x.x(mysql服务器的ip) -uxxx(授权的用户名) -pxxx(验证密码)&&&mysql -h10.10.87.105 -utest2 -pmopgaming&&&&Welcome to the MariaDB monitor. &C or \g.&&&&Your MariaDB connection id is 18&&&&Server version: 5.5.44-MariaDB MariaDB Server&&&&copyright (c) , Oracle, MariaDB Corporation Ab and others.&&&&Type '' or '\h' for help. Type '\c' to clear the current input statement.&&&&MariaDB [(none)]&&六、查询相关命令1 查询mysql用户列表:MariaDB [(none)]& select host,user from mysql.+--------------+-------+| host & & & & | user &|+--------------+-------+| 127.0.0.1 & &| root &|| ::1 & & & & &| root &|| localcentos7 | & & & || localcentos7 | root &|| localhost & &| & & & || localhost & &| root &|| localhost & &| test1 |+--------------+-------+MariaDB [(none)]& SELECT DISTINCT CONCAT('User: ''',user,'''@''',host,''';') AS query FROM mysql.+------------------------------+| query & & & & & & & & & & & &|+------------------------------+| User: 'root'@'127.0.0.1'; & &|| User: 'root'@'::1'; & & & & &|| User: ''@'localcentos7'; & & || User: 'root'@'localcentos7'; || User: ''@'localhost'; & & & &|| User: 'root'@'localhost'; & &|| User: 'test1'@'localhost'; & |+------------------------------+2&查询授权状态:#mysql -uroot -p&&&&&&&&&&&&&&&&&&&&&&说明数据库状态信息保存在mysql数据库下。&&&&& select *+------+---------+-------+-------------+-------------+-------------+----------| Host | Db & & &| User &| Select_priv | Insert_priv | Update_priv | Delete_pri+------+---------+-------+-------------+-------------+-------------+-----------| % & &| test & &| & & & | Y & & & & & | Y & & & & & | Y & & & & & | Y & & & & & & & &| % & &| test\_% | & & & | Y & & & & & | Y & & & & & | Y & & & & & | Y & & & .......... &&&| % & &| test & &| test2 | Y & & & & & | Y & & & & & | N & & & & & | N & & & &&+------+---------+-------+-------------+-------------+-------------+-----------可见test2用户被授予的权限:只针对test数据库,有select,insert权限。PS:mysql库中授权表解析mysql授权表共有5个:user,db,host,tables_priv和columns_priv每个表用途和内容”user表:列出服务器的用户及其口令,并且指出他们有那种权限。在user表总启用的权限都是全局权限,并适用所有数据库。例如,某用户启用delete权限,则可以在任何表中删除记录。db表:列出具体数据库对应的权限。在这里指定的权限适用于一个数据库中所有表。host表:host表和db表结合使用在一个较好层次上控制特定主机对数据库的访问权限。这个表不受grant和revoke语句的影响,所以,可能根本用不到。tables_priv表指定表级别的权限,在这里指定的一个权限适用于一个表的所有列。columns_priv表指定表内列级别的权限,在这里指定的权限适用于一个表的特定列。参考资料:1.Linux下给mysql创建用户分配权限2.linux下创建mysql用户3.MySql中添加用户,新建数据库,用户授权,删除用户,修改密码4.MySQL中授权(grant)和撤销授权(revoke)
了这篇文章
类别:未分类┆阅读(0)┆评论(0)

我要回帖

更多关于 mysql中修改root密码 的文章

 

随机推荐