查看Ubuntu版本信息:
(base) root@iZbp1bdi32t0s1dsw2bwrmZ:~# cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=20.04
DISTRIB_CODENAME=focal
DISTRIB_DESCRIPTION="Ubuntu 20.04.3 LTS"
(base) root@iZbp1bdi32t0s1dsw2bwrmZ:~#
ubuntu20 apt 源里的mysql 已經(jīng)更新到 8.0, 可以直接安裝
安裝
sudo apt update # 更新源
sudo apt install mysql-server #安裝
安裝完成后查看msyql版本:
(base) root@iZbp1bdi32t0s1dsw2bwrmZ:~# mysql -V
mysql Ver 8.0.27-0ubuntu0.20.04.1 for Linux on x86_64 ((Ubuntu))
mysql 服務(wù)的狀態(tài)管理
systemctl status mysql # 查看狀態(tài),裝完后默認就啟動了,默認開機啟動
sudo systemctl disable mysql # 關(guān)閉開機啟動
sudo systemctl disable mysql # 設(shè)置開機啟動
sudo systemctl start mysql # 啟動 mysql 服務(wù)
sudo systemctl stop mysql # 關(guān)閉 mysql 服務(wù)
默認用戶
sudo mysql # 使用 root 用戶連入 mysql, 默認不需要密碼
sudo cat /etc/mysql/debian.cnf # 這里提供了另一個默認賬戶和密碼 debian-sys-maint,密碼是明文,只能在本地登錄
我們使用mysql空密碼登陸硬鞍,輸入:mysql -uroot -p后回車扛伍,顯示輸入密碼荧降,第一次登陸默認密碼為空完疫,直接回車即可登錄mysql每瞒。
(base) root@iZbp1bdi32t0s1dsw2bwrmZ:~# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 8.0.27-0ubuntu0.20.04.1 (Ubuntu)
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
登陸mysql后我們先修改一下root賬號密碼艺普,密碼規(guī)則這里是長度為8位华畏,有大寫字母谨敛,小寫字母媳荒。還有特符號抗悍。
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql>show databases;
mysql>use mysql;
mysql>CREATE USER 'root'@'%' IDENTIFIED BY 'Abcd@1234';
mysql>GRANT ALL ON *.* TO 'root'@'%';
mysql>ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'Abcd@1234';
允許遠程連接
mysql默認只能從本地登錄,允許從遠程登錄需要修改綁定地址.
修改配置文件,綁定ip修改為 0.0.0.0
sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf
#bind-address = 127.0.0.1
bind-address = 0.0.0.0
重啟mysql服務(wù)
sudo systemctl restart mysql.service
創(chuàng)建數(shù)據(jù)庫
卸載 mysql
sudo rm /var/lib/mysql/ -R
sudo rm /etc/mysql/ -R
sudo apt autoremove mysql* --purge