一.命令安装
默认安装mysql5.7。如果要安装8.0,请看 四:Ubuntu 18.04安装MySQL8.0数据库
1. sudo apt-get install mysql-server
2. sudo apt-get install mysql-client
3. sudo apt-get install libmysqlclient-dev
二. 首次登录mysql未设置密码 解决方案
//查看默认密码
sudo cat /etc/mysql/debian.cnf
//使用默认密码登入数据库
mysql -u debian-sys-maint -pnYdiJRJ0ZuDO2f8x
//修改密码-----root
use mysql;
update mysql.user set authentication_string=password('root') where user='root' and Host ='localhost';
update user set plugin="mysql_native_password";
flush privileges;
quit;
//重启数据库
sudo service mysql restart
//新密码“root”登入数据库
mysql -u root -proot
三: navicat 远程无法登入
错误一: 2003-Can't connect to Mysql on '主机名'(10061)
//修改 配置文件
/etc/mysql/mysql.conf.d
sudo vi mysqld.cnf
# localhost which is more compatible and is not less secure.
#bind-address = 127.0.0.1
bind-address = 0.0.0.0
错误二: 1130 - Host XXX is not allowed to connect to this MySQL server。
use mysql;
select host from user where user='root';
update user set host = '%' where user ='root';
flush privileges;
错误三: 1251- Client does not support authentication protocol requested by server;consider upgrading Mysql client
原因:目前是caching_sha2_password 客户端是mysql_native_password
查看配置项
select host,user,plugin,authentication_string from mysql.user;
//caching_sha2_password 修改为mysql_native_password
//ALTER USER 'root'@'localhost' IDENTIFIED BY 'root' PASSWORD EXPIRE NEVER;
ALTER USER 'root'@'%' IDENTIFIED BY 'root' PASSWORD EXPIRE NEVER;
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'root';
FLUSH PRIVILEGES;
四: Ubuntu 18.04安装MySQL8.0数据库
//卸载mysql5.7
sudo apt-get autoremove --purge mysql-server-5.7
sudo apt-get remove mysql-common
sudo rm -rf /etc/mysql/ /var/lib/mysql
//下载deb文件
https://dev.mysql.com/downloads/repo/apt/
sudo dpkg -i mysql-apt-config_0.8.15-1_all.deb
//选择8.0数据库
MySQL Server & Cluster (Currently selected: mysql-8.0)
MySQL Tools & Connectors (Currently selected: Enabled)
下载数据库
sudo apt-get update
sudo apt-get install mysql-server
五: docker MYSQL
docker run --name mysql --privileged=true --restart always -p 3306:3306 -v /home/qiqi/mysql/data:/var/lib/mysql -v /home/qiqi/mysql/conf.d:/etc/mysql/conf.d -e MYSQL_ROOT_PASSWORD=123456 -d
alter user 'root'@'localhost' identified by 'ONEpiece0915@';
GRANT ALL ON *.* TO ' root '@'%';
alter user 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'ONEpiece0915@';
FLUSH PRIVILEGES;