美文网首页
树莓派安装MySQL

树莓派安装MySQL

作者: hellity | 来源:发表于2022-05-15 00:27 被阅读0次
安装:
sudo apt-get install mariadb-server
安装后无密码直接登录:
sudo mysql # sudo 必填 否则登录不上
初始化(可设置 root 密码):
sudo mysql_secure_installation # sudo 必填 否则出错。会询问你是否删除或者保留测试用数据库和用户

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] y
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] y
 ... Success!

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] y
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!
一. 创建用户

命令:CREATE USER 'username'@'host' IDENTIFIED BY 'password';

说明:
username:你将创建的用户名
host:指定该用户在哪个主机上可以登陆,如果是本地用户可用localhost,如果想让该用户可以从任意远程主机登陆,可以使用通配符%
password:该用户的登陆密码,密码可以为空,如果为空则该用户可以不需要密码登陆服务器
例子:

CREATE USER 'dog'@'localhost' IDENTIFIED BY '123456';
CREATE USER 'pig'@'192.168.1.101_' IDENDIFIED BY '123456';
CREATE USER 'pig'@'%' IDENTIFIED BY '123456';
CREATE USER 'pig'@'%' IDENTIFIED BY '';
CREATE USER 'pig'@'%';
三.设置与更改用户密码

命令:SET PASSWORD FOR 'username'@'host' = PASSWORD('newpassword');
如果是当前登陆用户用:SET PASSWORD = PASSWORD("newpassword");
例子:SET PASSWORD FOR 'pig'@'%' = PASSWORD("123456");

查看当前的数据库:show databases;
创建数据库:create database MyDB_one;
导入sql文件:mysql> source /opt/test.sql;
查看表结构:DESCRIBE 表名; 或者desc 表名;
增加字段(列):alter table purchase add warehoused int(2);
修改表数据:

update purchase set warehoused='1' where purchase_id=22;
('update purchase set warehoused={0} where purchase_id={1}').format('1',ids) # flask 中sql语句的写法

删除表、表数据的方式:

  1. 当你不再需要该表时, 用 drop; drop table 表名;
  2. 当你仍要保留该表,但要删除所有数据表记录时, 用 truncate; truncate table 表名;
  3. 当你要删除部分记录或者有可能会后悔的话, 用 delete。delete from 表名 where id='1'; 或者 delete from 表名;

Sqlalchemy filter与filter_by查询语法

Mysql查询、修改

创建一个表

DROP TABLE IF EXISTS `category`;
CREATE TABLE `category`  (
  `category_id` int(11) NOT NULL AUTO_INCREMENT,
  `category_name` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  PRIMARY KEY (`category_id`) USING BTREE,
  UNIQUE INDEX `category_name`(`category_name`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 9 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;

相关文章

  • 树莓派Docker上安装Mysql

    树莓派Docker上安装Mysql 在树莓派上官方mysql镜像无法使用,因为树莓派的架构为arm这里使用的映像是...

  • 树莓派下安装mysql

    树莓派下安装mysql 下载msyql服务器 如果显示没有下载任何包,表示系统已经安装了mysql,在树莓派上的m...

  • 树莓派技术网站导航

    树莓派官网 安装 树莓派Mac OS X下安装系统开启ssh登陆 使用教程 树莓派实验室树莓派吧树莓派中文站 项目...

  • 树莓派安装MySQL

    参考 树莓派安装mysql[https://blog.csdn.net/u010177891/article/de...

  • 树莓派内网穿透 Ngrok

    部署准备 go语言安装 树莓派和vps安装go的方式有所不同,树莓派下需要编译 树莓派安装go参考 http://...

  • 树莓派安装MYSQL

    1.安装mysql 2.配置远程连接 3.修改root密码 4.开启root远程登录权限 5.重启mysql服务

  • 树莓派安装mysql

    步骤 安装 mysql server 安装完毕以后,root密码默认为空。即任意密码都可以登录。 设置root密码...

  • 树莓派安装MySQL

    安装: 安装后无密码直接登录: 初始化(可设置 root 密码): 一. 创建用户 命令:CREATE USER ...

  • Docker应用:MYSQL通过UDF主动刷新数据到Redis

    笔者在WSL中安装docker失败,在树莓派中安装docker成功,但是找到的docker镜像mysql2re...

  • 可移动的图像识别小车(树莓派+摄像头)

    熟悉树莓派 树莓派介绍 树莓派安装系统 picamera的API 树莓派连接显示器不亮屏的解决方案 树莓派摄像头的...

网友评论

      本文标题:树莓派安装MySQL

      本文链接:https://www.haomeiwen.com/subject/kudvurtx.html