1. 安装mysql
执行命令
pi@raspberrypi:~ $ sudo apt-get install mysql-server
结果:
pi@raspberrypi:~ $ sudo apt-get install mysql-server -f正在读取软件包列表... 完成正在分析软件包的依赖关系树正在读取状态信息... 完成没有可用的软件包 mysql-server,但是它被其它的软件包引用了。这可能意味着这个缺失的软件包可能已被废弃,或者只能在其他发布源中找到然而下列软件包会取代它:mariadb-server-10.0E: 软件包 mysql-server 没有可安装候选
- 根据提示安装 mariadb-server-10.0
pi@raspberrypi:~ $ sudo apt-get install mariadb-server-10.0
结果:
正在设置 mariadb-server-core-10.0 (10.0.28-2+b1) ...正在设置 libhttp-message-perl (6.18-1) ...正在设置 libcgi-pm-perl (4.40-1) ...正在设置 libhtml-template-perl (2.97-1) ...正在设置 mariadb-server-10.0 (10.0.28-2+b1) ...正在设置 libcgi-fast-perl (1:2.13-1) ...正在处理用于 systemd (241-7~deb10u3+rpi1) 的触发器 ...正在处理用于 man-db (2.8.5-2) 的触发器 ...正在处理用于 libc-bin (2.28-10+rpi1) 的触发器 ...pi@raspberrypi:~ $
2. 设置root密码
安装完毕以后,root密码默认为空。即任意密码都可以登录
#执行pi@raspberrypi:~ $ sudo mysql -u rootWelcome to the MariaDB monitor. Commands end with ; or \g.Your MariaDB connection id is 42Server version: 10.0.28-MariaDB-2+b1 Raspbian testing-stagingCopyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.MariaDB [(none)]>
设置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;
3.开启远程登录
开启远程登录
$ 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;
ok 可以远程访问了
