一、连接步骤
navicat新建mysql连接,连接名随意,主机localhost,端口3306,用户名root,密码为root账户对应的密码,忘记密码需要重置,测试连接,连接成功。
二、command not found mysql
需要配置sql环境变量后才能找到
打开终端,输入
vim .bash_profile
输入 i 进入编辑界面,添加以下内容
export PATH=$PATH:/usr/local/mysql/bin
按下esc键,输入 :wq 保存退出
使配置文件生效
source .bash_profile
三、启用关闭SQL服务
方法一:
系统偏好设置-mysql,点击关闭按钮输入电脑密码后关闭。
如果关闭失败,取消勾选开机自动启动选项并输入电脑密码,重启电脑后关闭。
方法二:
查看mysql 的 pid
ps -ef | grep mysqld
看到 mysql 的pid 为2796
然后kill 掉这个进程:
sudo kill 2796
输入电脑密码,成功杀掉进程。再次查看:
ps -ef | grep mysqld
可以看到mysql进程已关闭
方法三
启动MySQL服务
sudo /usr/local/mysql/support-files/mysql.server start
停止MySQL服务
sudo /usr/local/mysql/support-files/mysql.server stop
重启MySQL服务
sudo /usr/local/mysql/support-files/mysql.server restart
四、重置密码
使用以上各方法停掉所有mysql服务后,输入指令:
sudo su
输入电脑密码,然后切换到mysql的bin目录 :
cd /usr/local/mysql/bin
禁止mysql验证功能, 开启--skip-grant-tables模式:
./mysqld_safe --skip-grant-tables --skip-networking &
新建一个终端窗口,不要关闭当前窗口
cd /usr/local/mysql/bin/
mysql -u root
出现mysql> 即成功
重置密码语句:
mysql> UPDATE mysql.user SET password=PASSWORD(’新密码’) WHERE User=’root’;
mysql> UPDATE mysql.user SET authentication_string=PASSWORD(’新密码’) WHERE User=’root’
五、一些报错总结
(一)navicat报错2059:
报错原因
由于目前已有的客户端连接软件不支持mysql 8新增加的加密方式caching_sha2_password
,所以要修改用户的加密方式,改为老的加密验证方式。
解决办法
1.进入SQL:
mysql -uroot -p
输入mysql密码
2.查看加密方式,
show variables like 'default_authentication_plugin';
3.如果是:caching_sha2_password,则把加密方式改成
mysql_native_password,123456为新的sql密码:
mysql>alter USER root@localhost identified with mysql_native_password BY '123456';
3.连接成功
(二)进入sql后修改密码时报错1290:
ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement
报错原因
开启了--skip-grant-tables模式,此时需要恢复原来的模式。
解决方法
1.在SQL中执行以下指令
mysql> set global read_only=0;
2.刷新配置环境
mysql> flush privileges;
3.执行命令关闭数据库只读属性:
mysql> show variables like '%read_only%';
4.正常修改密码
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
或者更改加密方式并修改密码(navicat报错2059时使用)
alter USER root@localhost identified with mysql_native_password BY 'Bxlxb99.';
(三)navicat报错2003
2003 - Can't connect to MySQL server on ……(61 "Connection refused")
解决方法
编辑连接--高级--使用套连字:
(四) 进入sql时报错1045
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
报错原因
mysql -uroot -p后输入sql密码,提示1045,原因是密码错误
解决方法
1.切换到管理员
sudo su
输入电脑密码
2. 关闭sql
sh-3.2# /usr/local/mysql/support-files/mysql.server stop
3.切换到bin目录并且关闭验证,跳过安全检查
cd /usr/local/mysql/bin
./mysqld_safe --skip-grant-tables &
4.保持当前终端窗口,再打开一个终端窗口mysql直接登录 ,然后把root密码设置为空或新密码
mysql-uroot -p
update mysql.user set authentication_string='' where user='root';
5.普通用户可以正常访问MySQL了,密码为空点击回车或者输入对应的密码