徐小玉的博客。
分类: Mysql/postgreSQL
2018-04-05 21:03:49
(1).进入/usr/local/mysql/bin,查看此目录下是否有mysql
(2).执行vim ~/.bash_profile
在该文件中添加mysql/bin的目录
PATH=$PATH:/usr/local/mysql/bin
添加完成后,按esc,然后输入wq保存。
(3).最后在命令行输入source ~/.bash_profile
登陆:
mysql -u root -p mysql
# 登陆的时候这样的错误:
mysql -u root -p
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
解决方法:
1: 进入系统偏好,关闭数据库(或者ps杀掉)
2: 在终端:
$ cd /usr/local/mysql/bin
$ sudo su。#root
## 启动安全模式:
3:./mysqld_safe --skip-grant-tables &
##再打开一个终端
4: mysql -u -root。 #。 无需密码进入数据库
# 5: to change the password
UPDATE mysql.user SET authentication_string = PASSWORD('newpasswd')
WHERE User = 'root' AND Host = 'localhost';
FLUSH PRIVILEGES;
# it is like:
mysql> UPDATE mysql.user SET authentication_string = PASSWORD('newpasswd')
-> WHERE User = 'root' AND Host = 'localhost';
Query OK, 1 row affected, 1 warning (0.02 sec)
Rows matched: 1 Changed: 1 Warnings: 1
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.01 sec)
#6: 之后退出mysql,输入以下命令退出安全模式。
/usr/local/mysql/share/mysql.server start
实际这里我并没成功,可能是和人家的版本不同,所以我杀掉的:
ps -ef |grep mysql, find the process and kill them
然后再重启数据库。再登陆
mysql -u root -p
用新密码就可以登陆了
若需要修改密码,请:
/usr/local/mysql/bin/mysqladmin -u root -p password
Enter password:
New password:
Confirm new password: