ubuntu下安装mysql

ubuntu自带了mysql,使用apt-get安装即可

sudo apt-get install mysql-server
sudo apt-get install mysql-client

用以下命令检查MySQL是否运行:

sudo netstat -tap | grep mysql

我这里显示

tcp        0      0 localhost:mysql         0.0.0.0:*                     LISTEN      6204/mysqld 

说明安装成功。

安装完毕以后,用以下命令登录

mysql -u root -p

会提示

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

此时,打开/etc/mysql/debian.cnf文件,注意,不是mysql.cnf

sudo vim debian.cnf

默认的user是debian-sys-maint,maint的意思是维修、保养,mysql默认创建了一个运维角色。

password 项后面的复杂字符串,可能是个加密串,直接修改成其它密码无效,所以,老老实实地用原来的,不过可以复制以后粘贴到需要输入密码的地方。

mysql -u debian-sys-maint -pwg

登录成功以后,设置root的密码,如果你用这种方式不成功:

update mysql.user set authentication_string=password('666666') where user='root'and Host = 'localhost';

那就试试下面这种(来自:https://www.cnblogs.com/leolztang/p/5094930.html

update mysql.user set authentication_string=PASSWORD('666666'), plugin='mysql_native_password' where user='root';

我用第二种方法设置成功。

 

至此,ubuntu下的mysql安装完成。

 

posted @ 2019-03-06 01:03  火军刀  阅读(339)  评论(0编辑  收藏  举报