步驟
安裝 mysql server
$ sudo apt-get update
$ sudo apt-get install mysql-server
安裝完畢以后,root密碼默認(rèn)為空。即任意密碼都可以登錄。
$ sudo mysql -u root
$ 回車登錄數(shù)據(jù)庫
# 出現(xiàn)下面提示,表示成功
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 13
Server version: 10.1.37-MariaDB-0+deb9u1 Raspbian 9.0
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]>
# MariaDB是一個完全兼容mysql的數(shù)據(jù)庫,具體可以自行百度。
設(shè)置root密碼
MariaDB [(none)]> use mysql;
MariaDB [mysql]> update user set plugin='mysql_native_password' where user='root';
MariaDB [mysql]> UPDATE user SET password=PASSWORD('root的密碼') WHERE user='root';
MariaDB [mysql]> flush privileges;
MariaDB [mysql]> exit;
操作Mysql
$ sudo /etc/init.d/mysql restart
# mysql的其他操作 status、start、stop、restart
開啟遠(yuǎn)程訪問
- 允許遠(yuǎn)程登錄
$ sudo vi /etc/mysql/mariadb.conf.d/50-server.cnf
# 將bind-address這行注釋掉
# 或者將127.0.0.1 這個值改為 0.0.0.0
# 然后重啟
$ sudo /etc/init.d/mysql restart
- 設(shè)置賬號權(quán)限
$ mysql -u root -p
$ 輸入密碼
MariaDB [(none)]> use mysql;
MariaDB [mysql]> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root的密碼' WITH GRANT OPTION;
MariaDB [mysql]> flush privileges;
然后就可以使用客戶端進(jìn)行連接了!