1. 安装mysql

执行命令

  1. pi@raspberrypi:~ $ sudo apt-get install mysql-server

结果:

  1. pi@raspberrypi:~ $ sudo apt-get install mysql-server -f
  2. 正在读取软件包列表... 完成
  3. 正在分析软件包的依赖关系树
  4. 正在读取状态信息... 完成
  5. 没有可用的软件包 mysql-server,但是它被其它的软件包引用了。
  6. 这可能意味着这个缺失的软件包可能已被废弃,
  7. 或者只能在其他发布源中找到
  8. 然而下列软件包会取代它:
  9. mariadb-server-10.0
  10. E: 软件包 mysql-server 没有可安装候选
  1. 根据提示安装 mariadb-server-10.0
  1. pi@raspberrypi:~ $ sudo apt-get install mariadb-server-10.0

结果:

  1. 正在设置 mariadb-server-core-10.0 (10.0.28-2+b1) ...
  2. 正在设置 libhttp-message-perl (6.18-1) ...
  3. 正在设置 libcgi-pm-perl (4.40-1) ...
  4. 正在设置 libhtml-template-perl (2.97-1) ...
  5. 正在设置 mariadb-server-10.0 (10.0.28-2+b1) ...
  6. 正在设置 libcgi-fast-perl (1:2.13-1) ...
  7. 正在处理用于 systemd (241-7~deb10u3+rpi1) 的触发器 ...
  8. 正在处理用于 man-db (2.8.5-2) 的触发器 ...
  9. 正在处理用于 libc-bin (2.28-10+rpi1) 的触发器 ...
  10. pi@raspberrypi:~ $

2. 设置root密码

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

  1. #执行
  2. pi@raspberrypi:~ $ sudo mysql -u root
  3. Welcome to the MariaDB monitor. Commands end with ; or \g.
  4. Your MariaDB connection id is 42
  5. Server version: 10.0.28-MariaDB-2+b1 Raspbian testing-staging
  6. Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.
  7. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  8. MariaDB [(none)]>

设置root密码

  1. MariaDB [(none)]> use mysql;
  2. MariaDB [mysql]> update user set plugin='mysql_native_password' where user='root';
  3. MariaDB [mysql]> UPDATE user SET password=PASSWORD('root的密码') WHERE user='root';
  4. MariaDB [mysql]> flush privileges;
  5. MariaDB [mysql]> exit;

3.开启远程登录

开启远程登录

  1. $ sudo vi /etc/mysql/mariadb.conf.d/50-server.cnf
  2. # 将bind-address这行注释掉
  3. # 或者将127.0.0.1 这个值改为 0.0.0.0
  4. # 然后重启
  5. $ sudo /etc/init.d/mysql restart

设置账号权限

  1. $ mysql -u root -p
  2. $ 输入密码
  3. MariaDB [(none)]> use mysql;
  4. MariaDB [mysql]> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root的密码' WITH GRANT OPTION;
  5. MariaDB [mysql]> flush privileges;

ok 可以远程访问了