一、忘记数据库密码时
(1)/etc/init.d/mysqld stop; //停止数据库服务
(2)mysqld_safe --user=mysql --skip-grant-tables --skip-networking &;//登录会跳过验证
(3)mysql -u root //root登录
(4)use mysql //切换数据库
(5)update user set authentication_string=password('root') where user='root';
//设置root用户的登录密码为root (注意:这里的mysql版本是5.7,字段为 authentication_string,如果字段报错,可以改为password)
(6)flush privileges; //立即生效
二、当本地的navicat访问对应linux服务器上的内容时,需要修改host字段为都可以访问,否则会出现Host 'xxx.xxx.xxx.xxx' is not allowed to connect this mysql的错误
(1)update user set host = '%' where user = 'root';
(2)flush privileges; //立即生效
三、linux环境下,执行mysql脚本
(1)mysql -u root -p //登录mysql
(2)source /test/test.sql //执行sql脚本