ubuntu MySQL安装

sudo apt-get install mysql-server

检查是否成功

sudo netstat -tap | grep mysql

ubuntu MySQL安装  ERROR 1698 (28000): Access denied for user

MySQL配置

数据库存放目录       /var/lib/mysql
配置文件存放目录 /usr/share/mysql
命令存放目录 /usr/bin

设置远程访问

默认MySQL占用3306端口,只是在IP127.0.0.1上监听, 拒绝其他ip访问

sudo vim /etc/mysql/mysql.conf.d/mysql.cnf
注释掉 bind-address=127.0.0.1

启动、停止、重启

启动 service mysql start
停止 service mysql stop
重启 server mysql restart

mysql 登录时忘记设置密码了

ERROR 1698 (28000): Access denied for user ‘root’@‘localhost’

mysql -uroot -p

报如下错

Enter password: 
ERROR 1698 (28000): Access denied for user 'root'@'localhost'

解决办法

sudo vim /etc/mysql/debian.cnf

ubuntu MySQL安装  ERROR 1698 (28000): Access denied for user


记住上面账号与密码,执行

mysql -u debian-sys-maint -p


use mysql;
update user set authentication_string=PASSWORD('1qaz2wsx') where user='root';
update user set plugin="mysql_native_password";
flush privileges;
quit;

重新启动mysql

/etc/init.d/mysql restart;

重新登陆即可, 密码1qaz2wsx