一.命令安裝
默認安裝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