树莓派安装mysql

浪尽此生 提交于 2020-02-01 00:13:58

步骤

安装 mysql server

 

$ sudo apt-get update
$ sudo apt-get install mysql-server

安装完毕以后,root密码默认为空。即任意密码都可以登录。

 

$ 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是一个完全兼容mysql的数据库,具体可以自行百度。

设置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

开启远程访问

  1. 允许远程登录

 

$ 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
  1. 设置账号权限

 

$ 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;

然后就可以使用客户端进行连接了!



作者:Pan_大宝
链接:https://www.jianshu.com/p/b258c5e2335b
来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!