命令行启动:
sudo /usr/local/mysql/support-files/mysql.server start
sudo /usr/local/mysql/support-files/mysql.server stop(关闭mysql, 可强制关闭进程:sudo pkill -9 mysql)
sudo /usr/local/mysql/support-files/mysql.server restart
如果期间出现错误, 更多的是权限问题:
sudo chmod -R 777 /usr/local/mysql/data
修改密码的三种方法:
第一种
mysql版本:5.7.17
1.首先我们要关闭mysql服务
sudo /usr/local/mysql/support-files/mysql.server stop
2.我们要用安全模式启动mysql
sudo /usr/local/mysql/bin/mysqld_safe --skip-grant-tables
3.使用root账号登录mysql服务
/usr/local/mysql/bin/mysql u root
4.修改root账号的密码(其实这运行的是sql语句)
update mysql.user set authentication_string=password('qingyun1') where user='root' and Host = 'localhost';
如果有必要,建议运行一下:flush privileges;
5.关闭安全模式,正常的重启mysql
sudo /usr/local/mysql/support-files/mysql.server restart
6.正常的使用root账号和密码连接mysql
/usr/local/mysql/bin/mysql -u root -p
第二种(好用)
如果忘记密码,强行修改:
1:停止Mysql服务sudo /usr/local/mysql/support-files/mysql.server stop
2:进入终端输入:cd /usr/local/mysql/bin/回车后;
登录管理员权限 sudo su回车后;
输入以下命令来禁止mysql验证功能./mysqld_safe --skip-grant-tables &回车后mysql会自动重启(偏好设置中mysql的状态会变成running)
3. 输入命令./mysql回车后,
输入命令FLUSH PRIVILEGES;
回车后,输入命令ALTER USER 'root'@'localhost' IDENTIFIED BY '你的新密码';
第三种
1. 停止 mysql server. 通常是在 '系统偏好设置' > MySQL > 'Stop MySQL Server'
或者:sudo /usr/local/mysql/support-files/mysql.server stop
2. 打开终端,输入:
sudo /usr/local/mysql/bin/mysqld_safe --skip-grant-tables
3. 打开另一个新终端,输入:
sudo /usr/local/mysql/bin/mysql -u root
UPDATE mysql.user SET authentication_string=PASSWORD('新密码') WHERE User='root';
FLUSH PRIVILEGES;
\q
4. 重启
sudo /usr/local/mysql/support-files/mysql.server restart
*以上方法针对 mysql V5.7.9,
旧版的mysql请使用:UPDATE mysql.user SET Password=PASSWORD('新密码') WHERE User='root';