安装
在命令行输入:sudo apt-get install mysql-server mysql-client
只需要等待安装即可。
安装完成,使用mysqld -V 验证是否安装成功。
问题
>>网上很多都说,安装时会输入root密码,我在安装时并没有提示,so,安装完成后,并不能用root账号登录。
ERROR 1698 (28000): Access denied for user 'root'@'localhost'
怎么解决呢?
1.打开 /etc/mysql/debian.cnf ,这个文件需要用root权限才能打开,用图形化界面的编辑器是不能点开的。
sudo cat /etc/mysql/debian.cnf。可以看到,文件中有user和passowrd,这个账户时可以直接登录mysql的,此时用此账户登录mysql:mysql -u你的账户 -p你的密码。
2.修改root账号的密码:
修改mysql数据库中的root账号的密码
首先切换数据库:
use mysql;
修改密码:
update user set authentication_string=password('123456') where user="root";(mysql5.7以后password字段更换为authentication_string)。
不能忘了最后一步,将数据库的更改拉到内存中:
flush privileges;
到此,我们的密码是修改了,可是root怎么还是登陆不上呢,别急,查看下user表:
select user,host,plugin from user where user = "root";
发现plugin 是auth_socket ,我们需要修改他为:mysql_native_password
update user set plugin = "mysql_native_password" where user = "root";
flush privileges;
到此,root账号正常登陆。
>>远程登录:
update user set host = ’%’ where user = 'root';
grant all privileges on *.* to root@'%' identified by "123456";
修改etc/mysql/mysql.conf.d/mysqld.cnf 中的bind-address = 127.0.0.1,将此行注释掉:加#号
#bind-address = 127.0.0.1
至此,root账号远程连接已经可用。