1.安装MySQL
sudo apt-get install mysql-server
提示安装mariadb-server-10.0
sudo apt-get install mariadb-server-10.0
2.登录MySQL
~$ mysql -u root -p
Enter password:
ERROR 1698 (28000): Access denied for user 'root'@'localhost'
解决步骤
(1)关闭MySQL
sudo service mysql stop
(2)以安全模式启动MySQL
sudo mysqld_safe --skip-grant-tables &
(3)登录mysql(不需要密码)
mysql -u root
(4)修改MySQL密码
update mysql.user set authentication_string=PASSWORD('password'), plugin='mysql_native_password' where user='root';
(5)重启MySQL服务,问题解决
~$ sudo service mysql stop
...
* MySQL Community Server 5.7.10 is stopped
~$ sudo service mysql start
..
* MySQL Community Server 5.7.10 is started
~$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.10 MySQL Community Server (GPL)
3.安装python编程接口
sudo apt-get install python-mysqldb
4.创建新的数据库
MariaDB[(none)]> CREATE DATABASE name;
Query OK, 1 row affected (0.00 sec)
5.查看数据库
MariaDB [(none)]> show databases
-> ;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| register |
+--------------------+
4 rows in set (0.01 sec)
注意:上面在配置的时候出现了ERROR 1698(28000)的问题,通过安全启动的方式解决了。但是下次重启树莓派的时候依然报错。
咱解决不了这个问题,先待定吧。上述无效的解决方式的参考链接。(如果遇到问题再来)
可以直接通过下面的命令进入MySQL不需要密码,直接以系统管理者来操作。
sudo mysql -u root
如何判断服务是否启动?或者说查看树莓派启动的服务有哪些。
sudo apt-get install chkconfig
chkconfig --list
参考链接:在树莓派上制作开机自启动程序及服务
二.远程连接MySQL数据库
通过在同一个局域网下的电脑的软件来连接树莓派上的数据库
参考链接
————————————————
版权声明:本文为CSDN博主「阳光正好sun」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qq_42759243/article/details/110320048