1、在Ubuntu安装mysql数据库
sudo apt install mysql-server
2、初次登录数据库
sudo mysql -u root –p
3、解决非sudo用户无法登录的问题:
1、进入sudo模式:
sudo -s
2、登陆数据库
mysql -u root -p
3、输入root的密码(默认为空)
Enter password:
4、更改加密方式
mysql>ALTER USER 'root'@'localhost' IDENTIFIED BY 'password' PASSWORD EXPIRE NEVER;
5、更改密码:(该例子中 1234为新密码)
mysql>ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '1234';
6、刷新:
mysql>FLUSH PRIVILEGES;
4、设置任意主机可登录
mysql -u root -p
mysql> use mysql;
mysql> update user set host='%' where user='root';
mysql> exit;
sudo vi /etc/mysql/mysql.conf.d/mysqld.cnf
注释掉下面一行
# bind-address = 127.0.0.1
重启mysql服务
/etc/init.d/mysql restart