步骤
安装 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
开启远程访问
- 允许远程登录
$ 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;
然后就可以使用客户端进行连接了!