樹莓派安裝mysql總結

樹莓派安裝mysql總結

1.遠程連接樹莓派

  • 通過ssh直接連接遠程服務
$ ssh [email protected]

2.命令行直接安裝mysql數據庫

  • 通過apt直接安裝mysql數據庫,說明:樹莓派提供了一個數據庫(MriaDB),相當於mysql使用,具體命令如下
$ sudo apt-get update
$ sudo apt-get install mariadb-server

3.修改數據庫密碼

$ sudo mysql -u root
$ 回車登錄數據庫
# 出現下面提示,表示成功

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 [(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;
  • 修改完成後重啓服務
$ sudo /etc/init.d/mysql restart
  • mysql的其他操作 status、start、stop、restart

4.其他

開啓遠程訪問

  • 允許遠程登錄
$ 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
  • 設置賬號權
$ 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;
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章