开启远程连接(raspberry pi ,ubuntu )
第一步
1
2root@rasp:~# vim /etc/mysql/mariadb.conf.d/50-server.cnf
# bind-address = 127.0.0.1第二步
进入MySQL1
2grant all privileges on *.* to root@"%" identified by "password" with grant option;
flush privileges;
第一行命令解释如下,.:第一个代表数据库名;第二个代表表名。这里的意思是所有数据库里的所有表都授权给用户。root:授予root账号。“%”:表示授权的用户IP可以指定,这里代表任意的IP地址都能访问MySQL数据库。“password”:分配账号对应的密码,这里密码自己替换成你的mysql root帐号密码。
第二行命令是刷新权限信息,也即是让我们所作的设置马上生效。
完全卸载mysql(Ver 15.1 Distrib 10.1.23-MariaDB)
1 | sudo apt purge mysql-* |
修改表
1 | create table if not exists emp( |
sql create view1
2
3
4create view view_name as
select column_name (s)
from table_name
where condition
create user
首先需要先创建用户, then 添加权限 到指定dbs/tables1
2create user 'user'@'localhost' identified by 'password' -- connect from localhost
create user 'user'@'%' identified by 'password' -- connect from local machine only
add privileges
1 | grant select ,insert ,update on dabasename.* to 'username'@'localhost' |
insert on duplicate key update
插入唯一key更新1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19CREATE TABLE iodku (
id INT AUTO_INCREMENT NOT NULL,
name VARCHAR(99) NOT NULL,
misc INT NOT NULL,
PRIMARY KEY(id),
UNIQUE(name)
) ENGINE=InnoDB;
INSERT INTO iodku (name, misc)
VALUES
('Leslie', 123),
('Sally', 456);
INSERT INTO iodku (name, misc)
VALUES
('Sally', 3333) -- should update
ON DUPLICATE KEY UPDATE -- `name` will trigger "duplicate key"
id = LAST_INSERT_ID(id),
misc = VALUES(misc);
SELECT LAST_INSERT_ID(); -- picking up existing value
insert ignore existing rows
插入忽略已经存在的行1
insert ignore into `people` (`id`, `name`)values('1','anni'),('2','anna');
1 | CREATE TABLE iodku ( |
insert select
1 | INSERT INTO `tableA` (`field_one`, `field_two`) |
delete vs Truncate
truncate
会重置 AUTO_INCREMENT
index 它比delete from 快在处理大量数据
any_value()
1 | SELECT item.item_id, ANY_VALUE(uses.tag) tag, |
sql join
z
mysql 查看系统变量
1 | show GLOBAL VARIABLES |
mysql 管理
- 正在执行的查询
1
show full processlist