1.先停止数据库服务器

service mysqld stop

2.vim /etc/my.cnf

3.配置文件添加skip-grant-tables

[root@VM_0_8_centos ~]# vim /etc/my.cnf# For advice on how to change settings please see# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html[mysqld]## 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.# log_bin## 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 = 2Mdatadir=/var/lib/mysqlsocket=/var/lib/mysql/mysql.sockskip-grant-tables      此处!!!!!!# Disabling symbolic-links is recommended to prevent assorted security riskssymbolic-links=0

systemctl restart mysql

5.登录数据库

mysql -uroot -p

如果询问密码,直接空密码登录

6.set password for root@localhost = password('123456');括号里面的密码你自己修改。

7.mysql -uroot -p123456 登录成功

PS:下面看下Mysql初始化root密码和允许远程访问

mysql默认root用户没有密码,输入mysql –u root 进入mysql

1、初始化root密码

进入mysql数据库

mysql>update user set password=PASSWORD(‘123456') where User='root';

a、改表。

mysql -u root –pmysql>use mysql;mysql>update user set host = '%' where user = 'root';mysql>select host, user from user;

例如,你想root使用123456从任何主机连接到mysql服务器。

mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
mysql>GRANT ALL PRIVILEGES ON *.* TO 'jack'@'10.10.50.127' IDENTIFIED BY '654321' WITH GRANT OPTION;mysql>FLUSH RIVILEGES
//进入MySQL服务器d:\mysql\bin\>mysql -h localhost -u root//赋予任何主机访问数据的权限mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION//使修改生效mysql>FLUSH PRIVILEGES//退出MySQL服务器mysql>EXIT

更多相关文章

  1. ES6 变量声明,箭头函数,数组方法,解构赋值,JSON,类与继承,模块化练习
  2. 浅谈Java中Collections.sort对List排序的两种方法
  3. Python list sort方法的具体使用
  4. python list.sort()根据多个关键字排序的方法实现
  5. android上一些方法的区别和用法的注意事项
  6. android实现字体闪烁动画的方法
  7. Android中dispatchDraw分析
  8. Android四大基本组件介绍与生命周期
  9. Android(安卓)MediaPlayer 常用方法介绍

随机推荐

  1. PHP百钱百鸡问题(三种解题思路及答案)
  2. 如何用PHP代码生成金字塔
  3. PHP路由库FastRoute的使用教程
  4. PHP日期时间快速入门(图文详解)
  5. PHP简单实现路由Route功能
  6. PHP中你必须了解的4种Array函数
  7. Mac电脑设置hosts的方法(图文步骤)
  8. 浅谈PHP连接MySQL数据库的三种方式
  9. PHP常用日期时间操作合集
  10. PHP开发者如何做好密码保护以及Laravel底