樹莓派安裝MySQL

參考 樹莓派安裝mysql

參考文章為在root管理權(quán)限下的所以不用加----> sudo

1.

我并沒有換源vi /etc/apt/sources.list.d/raspi.list 文件內(nèi)容如下

deb http://archive.raspberrypi.org/debian/ buster main
# Uncomment line below then 'apt-get update' to enable 'apt-get source'
#deb-src http://archive.raspberrypi.org/debian/ buster main

2.安裝

image.png
apt-get install mysql-server
#沒加sudo不夠權(quán)限

sudo apt-get install mysql-server
#安裝mysql提示可以安裝mariadb-server-10.0

apt-get install mariadb-server-10.0 
#安裝mariadb-server-10.0

Mariadb與MySQL的區(qū)別:

Mariadb與MySQL的區(qū)別

3.測試

加上sudo打開成功

4.設(shè)置ROOT密碼

后續(xù)步驟都是 參考 樹莓派安裝mysql

image.png

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;

5.啟動MySQL

sudo /etc/init.d/mysql restart
# mysql的其他操作    status、start、stop、restart

6.開啟遠程訪問

sudo vim /etc/mysql/mariadb.conf.d/50-server.cnf

#把下面bind-address注釋掉如:
>>
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
# bind-address            = 127.0.0.1
>>
# 或者將127.0.0.1 這個值改為  0.0.0.0

sudo /etc/init.d/mysql restart
# 然后重啟

7.設(shè)置遠程賬號

設(shè)置遠程賬號
mysql -u root -p
輸入root密碼
MariaDB [(none)]> use mysql;
MariaDB [mysql]> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root的密碼' WITH GRANT OPTION;
#這個密碼并沒和上方密碼一樣 沒報錯 估計遠程的賬戶和本地的獨立的 或者是更新了密碼? (下面9講到解釋)
MariaDB [mysql]> flush privileges;

然后就可以使用客戶端進行連接了!

8.查看數(shù)據(jù)庫

后續(xù)參考樹莓派——安裝MySQL數(shù)據(jù)庫并開啟遠程連接

image.png

MariaDB [(none)]>show databases;
#查看數(shù)據(jù)庫

MariaDB [(none)]> use mysql;
#選擇一個數(shù)據(jù)庫

MariaDB [mysql]> select host,user from user;
#查看當前有哪些用戶

9. 新增用戶

MariaDB [mysql]> grant all on *.* to 'zhang'@'%' identified by 'root';
#新增一個zhang用戶,密碼為root,可以在指定ip地址上遠程連接。這里授予了全部權(quán)限,自己可以根據(jù)實際情況給權(quán)限;允許所有ip請使用%代替ip。

MariaDB [mysql]> update user set host='%' where user='root' and host='localhost';
#如果不想增加記錄,只是想把某個已存在的用戶(例如root)修改成允許遠程主機訪問

MariaDB [mysql]> flush privileges;
#刷新mysql系統(tǒng)權(quán)限表

MariaDB [mysql]> exit
#退出數(shù)據(jù)庫

10.遠程連接數(shù)據(jù)庫

使用Navicat Premium工具

連接失敗再查原因

估計沒開3306端口

未能連接數(shù)據(jù)庫時3306端口情況
netstat -talnp
#查看端口開放情況發(fā)現(xiàn)3306端口ip為127.0.0.1:3306即僅限此ip連接




第二天啟動MySQL,使用Navicat Premium莫名其妙可以連接了

猜測開啟遠程連接后需要重啟樹莓派

僅做了如下測試參考 Linux下mysql服務(wù)存在,但是3306端口監(jiān)聽不存在,遠程連接不上
但因為只做了1.問題描述步驟后感覺能用Navicat Premium連接上就試了下成功了就沒試下去!!!

image.png

image.png

sudo /etc/init.d/mysql restart
#啟動MySQL

mysql -u root -p
#測試本地登錄MySQL 是可以已登錄 怎么服務(wù)啟動了

mysql -u root -h 127.0.0.1 -p
#測試通過127.0.0.1IP進入數(shù)據(jù)庫 成功

netstat -talnp
#查看端口開放情況發(fā)現(xiàn)3306端口ip變?yōu)?.0.0.0:3306了
Navicat Premium連上數(shù)據(jù)庫圖

完成!!!!

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容