{ "GNP": .6, "IndepYear": 1967, "Name": "Sealand", "_id": "SEA", "demographics": { "LifeExpectancy": 79, "Population": 27 }, "geography": { "Continent": "Europe", "Region": "British Islands", "SurfaceArea": 193 }, "government": { "GovernmentForm": "Monarchy", "HeadOfState": "Michael Bates" } }
sudo apt-get update
sudo apt-get install mysql-shell
sudo apt-get update
sudo apt-get install mysql-apt-config
sudo apt-get install mysql-shell
mysql80-community-release
mysql-community-release
sudo yum remove mysql-community-release
sudo dnf erase mysql-community-release
mysql80-community-release
sudo yum install mysql-shell
sudo dnf install mysql-shell
.pkg
user
mysqlsh --uri user
@localhost
world_x
{ "GNP": .6, "IndepYear": 1967, "Name": "Sealand", "_id": "SEA", "demographics": { "LifeExpectancy": 79, "Population": 27 }, "geography": { "Continent": "Europe", "Region": "British Islands", "SurfaceArea": 193 }, "government": { "GovernmentForm": "Monarchy", "HeadOfState": "Michael Bates" } }
+------+------------------+-------------+-----------------+------------------------+ | ID | Name | CountryCode | District | Info | +------+------------------+-------------+-----------------+------------------------+ | 1 | Kabul | AFG | Kabol |{"Population": 1780000} | | 2 | Qandahar | AFG | Qandahar |{"Population": 237500} | | 3 | Herat | AFG | Herat |{"Population": 186800} | | 4 | Mazar-e-Sharif | AFG | Balkh |{"Population": 127800} | | 5 | Amsterdam | NLD | Noord-Holland |{"Population": 731200} | | 6 | Rotterdam | NLD | Zuid-Holland |{"Population": 593321} | +------+------------------+-------------+-----------------+------------------------+
world_x
world_x
/tmp/
mysqlsh -u root --sql < /tmp/world_x-db/world_x.sql
Enter password:****
/tmp/
mysqlsh
Creating a Session to 'root@localhost/world_x' Enter password:name
@localhost/world_x****
name
world_x
mysql-js>
MySQL的JS >
mysqlsh
mysqlsh --help
\help
MySQL的JS > \help
\help
mysql-js> \help \connect
world_x
{field1: "value", field2 : 10, "field 3": null}
[
[{Name: "Aruba", _id: "ABW"}, {Name: "Angola", _id: "AGO"}]
db | db
|
db.getCollections() |
createCollection()
mysql-js> db.createCollection("flags")
<Collection:flags>
world_x
mysql-js> db.getCollections()
[
<Collection:countryinfo>,
<Collection:flags>
]
dropCollection()
mysql-js> session.dropCollection("world_x", "flags")
Query OK (0.04 sec)
add()
db
MySQL的JS > db
<Schema:world_x>
Schema:world_x
mysql-js> \use world_x
Schema `world_x` accessible through db.
mysql-js> db.countryinfo.add(
{
GNP: .6,
IndepYear: 1967,
Name: "Sealand",
_id: "SEA",
demographics: {
LifeExpectancy: 79,
Population: 27
},
geography: {
Continent: "Europe",
Region: "British Islands",
SurfaceArea: 193
},
government: {
GovernmentForm: "Monarchy",
HeadOfState: "Michael Bates"
}
}
)
Query OK, 1 item affected (0.02 sec)
_id
add()
_id
_id
find()
OR
AND
XOR
NOT
IN
!=
<>
>
>=
<
<=
&
<<
>>
+
*
~
find()
MySQL的JS > db.countryinfo.find()
【{“国民生产总值”:828,“indepyear”:空,“名”:“Aruba”、“_id”:“ABW”、“人口统计学”:{“寿命”:78.4000015258789,“人口”:103000 },{“地理”:“大陆”:“北方美国”、“区域“:“加勒比”,“表面积”:193 },“政府”:{“形式”:“nonmetropolitan荷兰领土”、“headofstate”:“比阿特丽克斯”}…}】240文件集(0秒)
Empty set (0.00 sec)
find()
world_x
_id
MySQL的JS > db.countryinfo.find("_id = 'AUS'")
【{“国民生产总值”:351182,“indepyear”:1901、“名”:“澳大利亚”、“_id”:“澳大利亚”、“人口统计学”:{“寿命”:79.80000305175781,“人口”:18886000 },{“地理”:“大陆”:“大洋洲”、“区域”:“澳大利亚和新西兰”,“表面积”:7741220 },“政府”:{“形式”:“君主立宪制、联合会”、“headofstate”:“Elisabeth II”} }】1文件集(0.01秒)
mysql-js> db.countryinfo.find("GNP > 500000")
...[output removed]
10 documents in set (0.00 sec)
mysql-js> db.countryinfo.find("GNP > 500000 and demographics.Population < 100000000")
...[output removed]
6 documents in set (0.00 sec)
mysql-js> db.countryinfo.find("GNP*1000000/demographics.Population > 30000")
...[output removed]
9 documents in set, 7 warnings (0.00 sec)
Warning (Code 1365): Division by 0
Warning (Code 1365): Division by 0
Warning (Code 1365): Division by 0
Warning (Code 1365): Division by 0
Warning (Code 1365): Division by 0
Warning (Code 1365): Division by 0
Warning (Code 1365): Division by 0
bind()
bind()
MySQL的JS > db.countryinfo.find("Name = :country").bind("country", "Italy")
【{“国民生产总值”:1161755,“indepyear”:1861、“名”:“意大利”、“_id”:“ITA”、“人口统计学”:{“寿命”:79,“人口”:57680000 },{“地理”:“大陆”:“欧洲”、“区域”:“欧洲南部”、“表面积”:301316 },“政府”:{“形式”:“共和国”、“headofstate”:“卡洛·阿泽利奥·钱皮”} }】1文件集(0.01秒)
fields()
MySQL的JS > db.countryinfo.find("GNP > 5000000").fields(["GNP", "Name"])
【{“国民生产总值”:8510700,“name”:“美国”} ] 1文件集(0.001秒)
mysql-js> db.countryinfo.find().
fields(mysqlx.expr('{"Name": upper(Name), "GNPPerCapita": GNP*1000000/demographics.Population}')).
limit(2)
[
{
"GNPPerCapita": 8038.834951456311,
"Name": "ARUBA"
},
{
"GNPPerCapita": 263.0281690140845,
"Name": "AFGHANISTAN"
}
]
2 documents in set (0.00 sec)
limit()
skip()
limit()
mysql-js> db.countryinfo.find().limit(5)
... [output removed]
5 documents in set (0.00 sec)
sort()
sort()
asc
mysql-js> db.countryinfo.find().sort(["IndepYear desc"]).limit(8)
... [output removed]
8 documents in set (0.00 sec)
limit()
skip()
MySQL的JS > db.countryinfo.find().sort(["IndepYear desc"]).limit(8).skip(1)
…【 输出中删除 ] 8文件集(0秒)
modify()
modify()
modify()
mysql-js> db.countryinfo.modify("_id = 'SEA'").
set("demographics", {LifeExpectancy: 78, Population: 28})
Query OK, 1 item affected (0.04 sec)
find()
modify()
mysql-js> db.countryinfo.modify("Name = 'Sealand'").unset("GNP")
Query OK, 1 item affected (0.01 sec)
find()
MySQL的JS > db.countryinfo.find("Name = 'Sealand'")
【{“indepyear”:1967年,“name”:“西兰公国”、“_id”:“海”、“人口统计学”:{“寿命”:78,“人口”:28 },“地理”:{“大陆”:“欧洲”、“区域”:“不列颠群岛”,“超级”:193 },“政府”:{“形式”:“君主”、“headofstate”:“迈克尔·贝茨”} }】1.文件集(0.001秒)
arrayAppend()
arrayDelete()
modify()
mysql-js> db.countryinfo.modify("true").set("Airports", [])
Query OK, 240 items affected (0.07 sec)
arrayAppend()
mysql-js> db.countryinfo.modify("Name = 'France'").arrayAppend("$.Airports", "ORY")
Query OK, 1 item affected (0.02 sec)
db.countryinfo.find("Name =
'France'")
arrayInsert()
MySQL的JS > db.countryinfo.modify("Name = 'France'").arrayInsert("$.Airports[0]", "CDG")
查询好,1项影响(0.04秒)
arrayDelete()
MySQL的JS > db.countryinfo.modify("Name = 'France'").arrayDelete("$.Airports[1]")
查询好,1项影响(0.03秒)
remove()
remove()
MySQL的JS > db.countryinfo.remove("_id = 'SEA'")
查询好,1项影响(0.02秒)
limit()
MySQL的JS > db.countryinfo.remove("true").limit(1)
查询好,1项影响(0.03秒)
mysql-js> db.countryinfo.remove("true").sort(["Name desc"]).limit(1)
Query OK, 1 item affected (0.02 sec)
world_x
mysql-js> db.countryinfo.find("demographics.Population < 100")
...[output removed]
8 documents in set (0.00 sec)
createIndex()
execute()
_id
createIndex()
field()
NULL
MySQL的JS > db.countryinfo.createIndex("pop"). field("demographics.Population", "INTEGER", false).execute()
查询好(0.04秒)
createIndex()
"Name"
true
mysql-js> db.countryinfo.createIndex("name", mysqlx.IndexType.UNIQUE).
field("Name", "TEXT(40)", true).execute()
Query OK (0.04 sec)
dropIndex()
mysql-js> db.countryinfo.dropIndex("pop").execute()
Query OK (0.58 sec)
InnoDB
db
MySQL的JS > db
Schema:world_x
mysql-js> \use world_x
world_x
mysql-js> db.getTables()
{
"city": <Table:city>,
"country": <Table:country>,
"countrylanguage": <Table:countrylanguage>
}
db. | |
db. | |
db. | |
db. |
world_x
insert()
insert()
insert()
world_x
mysql-js> db.city.insert("ID", "Name", "CountryCode", "District", "Info").
values(null, "Olympia", "USA", "Washington", '{"Population": 5000}')
Query OK, 1 item affected (0.01 sec)
mysql-js> db.city.insert("ID", "Name", "CountryCode").
values(null, "Little Falls", "USA").values(null, "Happy Valley", "USA")
Query OK, 2 item affected (0.03 sec)
insert()
select()
OR
AND
XOR
NOT
IN
!=
<>
>
>=
<
<=
&
<<
>>
+
*
~
select()
select()
MySQL的JS > db.city.select()
------ ------------ ------------- ------------ ------------------------- | ID |名字|国家|区|信息| ------ ------------ ------------- ------------ ------------------------- | 1 |喀布尔| AFG |喀布尔| { 1780000 }:“人口”| | 2 |坎大哈| AFG |坎大哈| { 237500 }:“人口”| | 3 |赫拉特| AFG |赫拉特| { 186800 } |“人口”……………| 4079 |拉| PSE |拉| {“人口”:92020 } | ------ ------- ---- ------------- ------------ ------------------------- 4082行集(0.01秒)
Empty set (0.00 sec)
select()
MySQL的JS > db.city.select(["Name", "CountryCode"])
给其他国家| name | | -------------------这| |喀布尔坎大哈| | | 12月12月12月| |赫拉特| | |马扎里沙里夫牺牲| 12月| |阿姆斯特丹|民盟|…|拉……| PSE | |奥林匹亚|美国| |小瀑布|美国| |欢乐谷|能给美国| 4082行在上(0秒)
where()
MySQL的JS > db.city.select(["Name", "CountryCode"]).where("Name like 'Z%'")
----------------------- ------------------ |名称| countrycode | ----------------------- ------------------ |该| | |公司|民盟民盟民盟| |兹沃勒| | |泽尼察|波黑| |扎加齐克| |萨拉戈萨一| | ESP | | |菲律宾三宝颜| | zahedan |伊朗| | zanjan |伊朗| | zabol |伊朗| |扎马| | JPN | zhezqazghan |哈萨克斯坦| |郑州| CHN |……………………| zeleznogorsk |罗斯| ----------------------- ------------------ 59行集(0秒)
bind()
method. For example, instead of using "Name = 'Z%' " as the condition, substitute a named placeholder consisting of a colon followed by a name that begins with a letter, such asbind()
MySQL的JS > db.city.select(["Name", "CountryCode"]). where("Name like :name").bind("name", "Z%")
AND
mysql-js> db.city.select(["Name", "CountryCode"]).
where("Name like 'Z%' and CountryCode = 'CHN'")
+----------------+-------------+
| Name | CountryCode |
+----------------+-------------+
| Zhengzhou | CHN |
| Zibo | CHN |
| Zhangjiakou | CHN |
| Zhuzhou | CHN |
| Zhangjiang | CHN |
| Zigong | CHN |
| Zaozhuang | CHN |
... ...
| Zhangjiagang | CHN |
+----------------+-------------+
22 rows in set (0.01 sec)
AND
OR
MySQL的JS > db.city.select(["Name", "CountryCode"]). where("Name like 'Z%' and (CountryCode = 'CHN' or CountryCode = 'RUS')")
------------------- ------------- |名字|国家| ------------------- ------------- |郑州| CHN | |淄博| CHN | |张家口| CHN | |株洲| CHN |……| zeleznogorsk |罗斯| ------------------- ------------- 29行集(0.01秒)
limit()
offSet()
limit()
mysql-js> db.country.select(["Code", "Name"]).limit(5)
+------+-------------+
| Code | Name |
+------+-------------+
| ABW | Aruba |
| AFG | Afghanistan |
| AGO | Angola |
| AIA | Anguilla |
| ALB | Albania |
+------+-------------+
5 rows in set (0.00 sec)
orderBy()
orderBy()
asc
mysql-js> db.country.select(["Code", "Name"]).orderBy(["Name desc"]).limit(3)
+------+------------+
| Code | Name |
+------+------------+
| ZWE | Zimbabwe |
| ZMB | Zambia |
| YUG | Yugoslavia |
+------+------------+
3 rows in set (0.00 sec)
limit()
offset()
MySQL的JS > db.country.select(["Code", "Name"]).orderBy(["Name desc"]).limit(3).offset(1)
------ ------------ |代码|名字| ------ ------------ | ZMB |赞比亚| |尤克|南斯拉夫| | |解说也门| ------ ------------三行集(0.001秒)
update()
set()
mysql-js> db.city.update().set("Name", "Beijing").where("Name = 'Peking'")
Query OK, 1 item affected (0.04 sec)
select()
MySQL的JS > db.city.select(["ID", "Name", "CountryCode", "District", "Info"]).where("Name = 'Beijing'")
------ ----------- ------------- ---------- ----------------------------- | ID |名字|国家|区|信息| ------ ----------- ------------- ---------- ----------------------------- | 1891 |北京| CHN |北京| { 7472000 }:“人口”| ------ ----------- ------------- ---------- ----------------------------- 1行集(0秒)
delete()
delete()
MySQL的JS > db.city.delete().where("Name = 'Olympia'")
查询好,1项影响(0.01秒)
world_x
JSON
world_x
+---------------+------------+-------+-------+---------+------------------+ | Field | Type | Null | Key | Default | Extra | +---------------+------------+-------+-------+---------+------------------+ | ID | int(11) | NO | PRI | null | auto_increment | | Name | char(35) | NO | | | | | CountryCode | char(3) | NO | | | | | District | char(20) | NO | | | | | Info | json | YES | | null | | +---------------+------------+-------+-------+---------+------------------+
values()
MySQL的JS > db.city.insert(). values(null, "San Francisco", "USA", "California", '{"Population":830000}')
查询好,1项影响(0.01秒)
mysql-js> db.city.select(["ID", "Name", "CountryCode", "District", "Info"]).
where("CountryCode = :country and Info->'$.Population' > 1000000").
bind('country', 'USA')
+------+----------------+-------------+----------------+-----------------------------+
| ID | Name | CountryCode | District | Info |
+------+----------------+-------------+----------------+-----------------------------+
| 3793 | New York | USA | New York | {"Population": 8008278} |
| 3794 | Los Angeles | USA | California | {"Population": 3694820} |
| 3795 | Chicago | USA | Illinois | {"Population": 2896016} |
| 3796 | Houston | USA | Texas | {"Population": 1953631} |
| 3797 | Philadelphia | USA | Pennsylvania | {"Population": 1517550} |
| 3798 | Phoenix | USA | Arizona | {"Population": 1321045} |
| 3799 | San Diego | USA | California | {"Population": 1223400} |
| 3800 | Dallas | USA | Texas | {"Population": 1188580} |
| 3801 | San Antonio | USA | Texas | {"Population": 1144646} |
+------+----------------+-------------+----------------+-----------------------------+
9 rows in set (0.01 sec)
world_x
{ "GNP": .6, "IndepYear": 1967, "Name": "Sealand", "_id": "SEA", "demographics": { "LifeExpectancy": 79, "Population": 27 }, "geography": { "Continent": "Europe", "Region": "British Islands", "SurfaceArea": 193 }, "government": { "GovernmentForm": "Monarchy", "HeadOfState": "Michael Bates" } }
+------+------------------+-------------+-----------------+------------------------+ | ID | Name | CountryCode | District | Info | +------+------------------+-------------+-----------------+------------------------+ | 1 | Kabul | AFG | Kabol |{"Population": 1780000} | | 2 | Qandahar | AFG | Qandahar |{"Population": 237500} | | 3 | Herat | AFG | Herat |{"Population": 186800} | | 4 | Mazar-e-Sharif | AFG | Balkh |{"Population": 127800} | | 5 | Amsterdam | NLD | Noord-Holland |{"Population": 731200} | | 6 | Rotterdam | NLD | Zuid-Holland |{"Population": 593321} | +------+------------------+-------------+-----------------+------------------------+
world_x
world_x
/tmp/
mysqlsh -u root --sql < /tmp/world_x-db/world_x.sql
Enter password:****
/tmp/
mysqlsh
--py Creating a Session toname
@localhost/world_xname
@localhost/world_x Enter password:****
name
--py
world_x
mysql-py>
MySQL服务器>。
mysqlsh --help
\help
MySQL服务器>。 \help
\help
mysql-py> \help \connect
world_x
{"field1": "value", "field2" : 10, "field 3": null}
[
[{"Name": "Aruba", "_id": "ABW"}, {"Name": "Angola", "_id": "AGO"}]
db | db
|
db.get_collections() |
create_collection()
mysql-py> db.create_collection("flags")
<Collection:flags>
world_x
mysql-py>db.get_collections()
[ <Collection:countryinfo>, <Collection:flags> ]
drop_collection()
mysql-py> session.drop_collection("world_x", "flags")
Query OK (0.04 sec)
add()
db
MySQL服务器>。 db
<Schema:world_x>
Schema:world_x
mysql-py> \use world_x
Schema `world_x` accessible through db.
mysql-py> db.countryinfo.add(
{
"GNP": .6,
"IndepYear": 1967,
"Name": "Sealand",
"_id": "SEA",
"demographics": {
"LifeExpectancy": 79,
"Population": 27
},
"geography": {
"Continent": "Europe",
"Region": "British Islands",
"SurfaceArea": 193
},
"government": {
"GovernmentForm": "Monarchy",
"HeadOfState": "Michael Bates"
}
}
)
Query OK, 1 item affected (0.02 sec)
_id
add()
_id
_id
find()
OR
AND
XOR
NOT
IN
!=
<>
>
>=
<
<=
&
<<
>>
+
*
~
find()
MySQL服务器>。 db.countryinfo.find()
【{“国民生产总值”:828,“indepyear”:空,“名”:“Aruba”、“_id”:“ABW”、“人口统计学”:{“寿命”:78.4000015258789,“人口”:103000 },{“地理”:“大陆”:“北方美国”、“区域“:“加勒比”,“表面积”:193 },“政府”:{“形式”:“nonmetropolitan荷兰领土”、“headofstate”:“比阿特丽克斯”}…}】240文件集(0秒)
Empty set (0.00 sec)
find()
world_x
_id
mysql-py> db.countryinfo.find("_id = 'AUS'")
【{“国民生产总值”:351182,“indepyear”:1901、“名”:“澳大利亚”、“_id”:“澳大利亚”、“人口统计学”:{“寿命”:79.80000305175781,“人口”:18886000 },{“地理”:“大陆”:“大洋洲”、“区域”:“澳大利亚和新西兰”,“表面积”:7741220 },“政府”:{“形式”:“君主立宪制、联合会”、“headofstate”:“Elisabeth II”} }】1文件集(0.01秒)
mysql-py> db.countryinfo.find("GNP > 500000")
...[output removed]
10 documents in set (0.00 sec)
mysql-py> db.countryinfo.find("GNP > 500000 and demographics.Population < 100000000")
...[output removed]
6 documents in set (0.00 sec)
mysql-py> db.countryinfo.find("GNP*1000000/demographics.Population > 30000")
...[output removed]
9 documents in set, 7 warnings (0.00 sec)
Warning (Code 1365): Division by 0
Warning (Code 1365): Division by 0
Warning (Code 1365): Division by 0
Warning (Code 1365): Division by 0
Warning (Code 1365): Division by 0
Warning (Code 1365): Division by 0
Warning (Code 1365): Division by 0
bind()
bind()
MySQL服务器>。 db.countryinfo.find("Name = :country").bind("country", "Italy")
【{“国民生产总值”:1161755,“indepyear”:1861、“名”:“意大利”、“_id”:“ITA”、“人口统计学”:{“寿命”:79,“人口”:57680000 },{“地理”:“大陆”:“欧洲”、“区域”:“欧洲南部”、“表面积”:301316 },“政府”:{“形式”:“共和国”、“headofstate”:“卡洛·阿泽利奥·钱皮”} }】1文件集(0.01秒)
fields()
MySQL服务器>。 db.countryinfo.find("GNP > 5000000").fields(["GNP", "Name"])
【{“国民生产总值”:8510700,“name”:“美国”} ] 1文件集(0.001秒)
mysql-py> db.countryinfo.find().\
fields(mysqlx.expr('{"Name": upper(Name), "GNPPerCapita": GNP*1000000/demographics.Population}')).\
limit(2)
[
{
"GNPPerCapita": 8038.834951456311,
"Name": "ARUBA"
},
{
"GNPPerCapita": 263.0281690140845,
"Name": "AFGHANISTAN"
}
]
2 documents in set (0.00 sec)
limit()
skip()
limit()
mysql-py> db.countryinfo.find().limit(5)
... [output removed]
5 documents in set (0.00 sec)
sort()
sort()
asc
mysql-py> db.countryinfo.find().sort(["IndepYear desc"]).limit(8)
... [output removed]
8 documents in set (0.00 sec)
limit()
skip()
MySQL服务器>。 db.countryinfo.find().sort(["IndepYear desc"]).limit(8).skip(1)
…【 输出中删除 ] 8文件集(0秒)
modify()
modify()
modify()
mysql-py> db.countryinfo.modify("_id = 'SEA'").\
set("demographics", {"LifeExpectancy": 78, "Population": 28})
Query OK, 1 item affected (0.04 sec)
find()
modify()
mysql-py> db.countryinfo.modify("Name = 'Sealand'").unset("GNP")
Query OK, 1 item affected (0.01 sec)
find()
MySQL服务器>。 db.countryinfo.find("Name = 'Sealand'")
【{“indepyear”:1967年,“name”:“西兰公国”、“_id”:“海”、“人口统计学”:{“寿命”:78,“人口”:28 },“地理”:{“大陆”:“欧洲”、“区域”:“不列颠群岛”,“超级”:193 },“政府”:{“形式”:“君主”、“headofstate”:“迈克尔·贝茨”} }】1.文件集(0.001秒)
array_append()
array_delete()
modify()
mysql-py> db.countryinfo.modify(True).set("Airports", [])
Query OK, 240 items affected (0.07 sec)
array_append()
mysql-py> db.countryinfo.modify("Name = 'France'").array_append("$.Airports", "ORY")
Query OK, 1 item affected (0.02 sec)
db.countryinfo.find("Name =
'France'")
array_insert()
MySQL服务器>。 db.countryinfo.modify("Name = 'France'").array_insert("$.Airports[0]", "CDG")
查询好,1项影响(0.04秒)
array_delete()
MySQL服务器>。 db.countryinfo.modify("Name = 'France'").array_delete("$.Airports[1]")
查询好,1项影响(0.03秒)
remove()
remove()
MySQL服务器>。 db.countryinfo.remove("_id = 'SEA'")
查询好,1项影响(0.02秒)
limit()
MySQL服务器>。 db.countryinfo.remove(True).limit(1)
查询好,1项影响(0.03秒)
mysql-py> db.countryinfo.remove(True).sort(["Name desc"]).limit(1)
Query OK, 1 item affected (0.02 sec)
world_x
mysql-js> db.countryinfo.find("demographics.Population < 100")
...[output removed]
8 documents in set (0.00 sec)
create_index()
execute()
_id
create_index()
field()
NULL
MySQL的JS > db.countryinfo.create_index("pop").\ field("demographics.Population", "INTEGER", False).execute()
查询好(0.04秒)
create_index()
"Name"
True
mysql-js> db.countryinfo.create_index("name", mysqlx.IndexType.UNIQUE).\
field("Name", "TEXT(40)", True).execute()
Query OK (0.04 sec)
drop_index()
mysql-js> db.countryinfo.drop_index("pop").execute()
Query OK (0.58 sec)
InnoDB
db
MySQL服务器>。 db
<Schema:world_x>
Schema:world_x
mysql-py> \use world_x
Schema `world_x` accessible through db.
world_x
mysql-py> db.get_tables()
{
"city": <Table:city>,
"country": <Table:country>,
"countrylanguage": <Table:countrylanguage>
}
db. | |
db. | |
db. | |
db. |
world_x
insert()
insert()
insert()
world_x
mysql-py> db.city.insert("ID", "Name", "CountryCode", "District", "Info").\
values(None, "Olympia", "USA", "Washington", '{"Population": 5000}')
Query OK, 1 item affected (0.01 sec)
mysql-py> db.city.insert("ID", "Name", "CountryCode").\
values(None, "Little Falls", "USA").values(None, "Happy Valley", "USA")
Query OK, 2 item affected (0.03 sec)
insert()
select()
OR
AND
XOR
NOT
IN
!=
<>
>
>=
<
<=
&
<<
>>
+
*
~
select()
select()
MySQL服务器>。 db.city.select()
------ ------------ ------------- ------------ ------------------------- | ID |名字|国家|区|信息| ------ ------------ ------------- ------------ ------------------------- | 1 |喀布尔| AFG |喀布尔| { 1780000 }:“人口”| | 2 |坎大哈| AFG |坎大哈| { 237500 }:“人口”| | 3 |赫拉特| AFG |赫拉特| { 186800 } |“人口”……………| 4079 |拉| PSE |拉| {“人口”:92020 } | ------ ------- ---- ------------- ------------ ------------------------- 4082行集(0.01秒)
Empty set (0.00 sec)
select()
MySQL服务器>。 db.city.select(["Name", "CountryCode"])
给其他国家| name | | -------------------这| |喀布尔坎大哈| | | 12月12月12月| |赫拉特| | |马扎里沙里夫牺牲| 12月| |阿姆斯特丹|民盟|…|拉……| PSE | |奥林匹亚|美国| |小瀑布|美国| |欢乐谷|能给美国| 4082行在上(0秒)
where()
MySQL服务器>。 db.city.select(["Name", "CountryCode"]).where("Name like 'Z%'")
----------------------- ------------------ |名称| countrycode | ----------------------- ------------------ |该| | |公司|民盟民盟民盟| |兹沃勒| | |泽尼察|波黑| |扎加齐克| |萨拉戈萨一| | ESP | | |菲律宾三宝颜| | zahedan |伊朗| | zanjan |伊朗| | zabol |伊朗| |扎马| | JPN | zhezqazghan |哈萨克斯坦| |郑州| CHN |……………………| zeleznogorsk |罗斯| ----------------------- ------------------ 59行集(0秒)
bind()
method. For example, instead of using "Name = 'Z%' " as the condition, substitute a named placeholder consisting of a colon followed by a name that begins with a letter, such asbind()
MySQL服务器>。 db.city.select(["Name", "CountryCode"]).\ where("Name like :name").bind("name", "Z%")
AND
mysql-py> db.city.select(["Name", "CountryCode"]).\
where("Name like 'Z%' and CountryCode = 'CHN'")
+----------------+-------------+
| Name | CountryCode |
+----------------+-------------+
| Zhengzhou | CHN |
| Zibo | CHN |
| Zhangjiakou | CHN |
| Zhuzhou | CHN |
| Zhangjiang | CHN |
| Zigong | CHN |
| Zaozhuang | CHN |
... ...
| Zhangjiagang | CHN |
+----------------+-------------+
22 rows in set (0.01 sec)
AND
OR
MySQL服务器>。 db.city.select(["Name", "CountryCode"]).\ where("Name like 'Z%' and (CountryCode = 'CHN' or CountryCode = 'RUS')")
------------------- ------------- |名字|国家| ------------------- ------------- |郑州| CHN | |淄博| CHN | |张家口| CHN | |株洲| CHN |……| zeleznogorsk |罗斯| ------------------- ------------- 29行集(0.01秒)
limit()
offset()
limit()
mysql-py> db.country.select(["Code", "Name"]).limit(5)
+------+-------------+
| Code | Name |
+------+-------------+
| ABW | Aruba |
| AFG | Afghanistan |
| AGO | Angola |
| AIA | Anguilla |
| ALB | Albania |
+------+-------------+
5 rows in set (0.00 sec)
order_by()
order_by()
asc
mysql-py> db.country.select(["Code", "Name"]).order_by(["Name desc"]).limit(3)
+------+------------+
| Code | Name |
+------+------------+
| ZWE | Zimbabwe |
| ZMB | Zambia |
| YUG | Yugoslavia |
+------+------------+
3 rows in set (0.00 sec)
limit()
offset()
MySQL服务器>。 db.country.select(["Code", "Name"]).order_by(["Name desc"]).limit(3).offset(1)
------ ------------ |代码|名字| ------ ------------ | ZMB |赞比亚| |尤克|南斯拉夫| | |解说也门| ------ ------------三行集(0.001秒)
update()
set()
mysql-py> db.city.update().set("Name", "Beijing").where("Name = 'Peking'")
Query OK, 1 item affected (0.04 sec)
select()
MySQL服务器>。 db.city.select(["ID", "Name", "CountryCode", "District", "Info"]).where("Name = 'Beijing'")
------ ----------- ------------- ---------- ----------------------------- | ID |名字|国家|区|信息| ------ ----------- ------------- ---------- ----------------------------- | 1891 |北京| CHN |北京| { 7472000 }:“人口”| ------ ----------- ------------- ---------- ----------------------------- 1行集(0秒)
delete()
delete()
MySQL服务器>。 db.city.delete().where("Name = 'Olympia'")
查询好,1项影响(0.01秒)
world_x
JSON
world_x
+---------------+------------+-------+-------+---------+------------------+ | Field | Type | Null | Key | Default | Extra | +---------------+------------+-------+-------+---------+------------------+ | ID | int(11) | NO | PRI | null | auto_increment | | Name | char(35) | NO | | | | | CountryCode | char(3) | NO | | | | | District | char(20) | NO | | | | | Info | json | YES | | null | | +---------------+------------+-------+-------+---------+------------------+
values()
MySQL服务器>。 db.city.insert().\ values(None, "San Francisco", "USA", "California", '{"Population":830000}')
查询好,1项影响(0.01秒)
mysql-py> db.city.select(["ID", "Name", "CountryCode", "District", "Info"]).\
where("CountryCode = :country and Info->'$.Population' > 1000000").\
bind('country', 'USA')
+------+----------------+-------------+----------------+-----------------------------+
| ID | Name | CountryCode | District | Info |
+------+----------------+-------------+----------------+-----------------------------+
| 3793 | New York | USA | New York | {"Population": 8008278} |
| 3794 | Los Angeles | USA | California | {"Population": 3694820} |
| 3795 | Chicago | USA | Illinois | {"Population": 2896016} |
| 3796 | Houston | USA | Texas | {"Population": 1953631} |
| 3797 | Philadelphia | USA | Pennsylvania | {"Population": 1517550} |
| 3798 | Phoenix | USA | Arizona | {"Population": 1321045} |
| 3799 | San Diego | USA | California | {"Population": 1223400} |
| 3800 | Dallas | USA | Texas | {"Population": 1188580} |
| 3801 | San Antonio | USA | Texas | {"Population": 1144646} |
+------+----------------+-------------+----------------+-----------------------------+
9 rows in set (0.01 sec)
shell> mysqlsh -u user
--sqlc -P 3306 -e "SHOW plugins"
shell> mysql -u user
-p -e "SHOW plugins"
+----------------------------+----------+--------------------+---------+---------+ | Name | Status | Type | Library | License | +----------------------------+----------+--------------------+---------+---------+ ... | mysqlx | ACTIVE | DAEMON | NULL | GPL | ... +----------------------------+----------+--------------------+---------+---------+
mysqlx=0
--mysqlx=0
-DWITH_MYSQLX=OFF
mysqlx_ssl_*
mysqlx_ssl_*
ssl-*
my.cnf
[mysqld]ssl-ca=ca1.pemssl-cert=server-cert1.pemssl-key=server-key1.pemmysqlx-ssl-ca=ca2.pemmysqlx-ssl-cert=server-cert2.pemmysqlx-ssl-key=server-key2.pem
mysqlx_ssl_*
tls_version
GRANT
require_secure_transport
SHA256_MEMORY
mysqlx_cache_cleaner
caching_sha2_password
ON
--mysqlx-bind-address=# | |
mysqlx_bind_address | |
* |
*
0.0.0.0
::
*
::ffff:127.0.0.1
--host=127.0.0.1
--host=::ffff:127.0.0.1
127.0.0.1
--mysqlx-connect-timeout[=
value
]
--mysqlx-connect-timeout=# | |
mysqlx_connect_timeout | |
30 | |
1 | |
1000000000 |
connect_timeout
--mysqlx-idle-worker-thread-timeout[=
value
]
--mysqlx-idle-worker-thread-timeout=# | |
mysqlx_idle_worker_thread_timeout | |
60 | |
0 | |
3600 |
--mysqlx-interactive-timeout=
value
]
--mysqlx-interactive-timeout=# | |
mysqlx_interactive_timeout | |
28800 | |
1 | |
2147483 |
mysqlx_wait_timeout
--mysqlx-max-allowed-packet[=
value
]
--mysqlx-max-allowed-packet=# | |
mysqlx_max_allowed_packet | |
1048576 | |
512 | |
1073741824 |
--mysqlx-max-connections[=
value
]
--mysqlx-max-connections=# | |
mysqlx_max_connections | |
100 | |
1 | |
65535 |
--mysqlx-min-worker-threads[=
value
]
--mysqlx-min-worker-threads=value | |
mysqlx_min_worker_threads | |
2 | |
1 | |
100 |
--mysqlx-port=# | |
mysqlx_port | |
33060 | |
1 | |
65535 |
port
--mysqlx-port-open-timeout[=
value
]
--mysqlx-port-open-timeout=# | |
mysqlx_port_open_timeout | |
0 | |
1 | |
120 |
--mysqlx-read-timeout=# | |
mysqlx_port_read_timeout | |
28800 | |
30 | |
2147483 |
--mysqlx-socket=file_name | |
mysqlx_socket | |
/tmp/mysqlx.sock |
mysqlx_socket
socket
socket
mysqlx_socket
socket
mysqlx_socket
mysqlx_socket
socket
socket
mysqlx_socket
socket=/home/sockets/mysqld/mysql.sockmysqlx_socket=/home/sockets/xplugin/xplugin.sock
MYSQLX_UNIX_ADDR
MYSQLX_UNIX_ADDR
MYSQL_UNIX_ADDR
/tmp/mysqlx.sock
--mysqlx-ssl-ca=file-name | |
mysqlx_ssl_ca | |
ssl_ca
--mysqlx-ssl-capath=dir_name | |
mysqlx_ssl_capath | |
ssl_capath
--mysqlx-ssl-cert=name | |
mysqlx_ssl_cert | |
ssl_cert
--mysqlx-ssl-cipher=name | |
ssl_cipher
--mysqlx-ssl-crl=file_name | |
mysqlx_ssl_crl | |
ssl_crl
--mysqlx-ssl-crlpath=directory_name | |
mysqlx_ssl_crlpath | |
ssl_crlpath
--mysqlx-ssl-key=file-name | |
mysqlx_ssl_key | |
ssl_key
--mysqlx-wait-timeout=value | |
mysqlx_wait_timeout | |
28800 | |
1 | |
2147483 |
mysqlx_wait_timeout
--mysqlx-write-timeout[=
value
]
--mysqlx-write-timeout=value | |
mysqlx_write_timeout | |
60 | |
1 | |
2147483 |
ON
--mysqlx-bind-address=value | |
mysqlx_bind_address | |
* |
bind_address
--mysqlx-connect-timeout=value | |
mysqlx_connect_timeout | |
30 | |
1 | |
1000000000 |
connect_timeout
mysqlx_document_id_unique_prefix
--mysqlx-document-id-unique-prefix=value | |
mysqlx_document_id_unique_prefix | |
0 | |
0 | |
65535 |
mysqlx_idle_worker_thread_timeout
--mysqlx-idle-worker-thread-timeout=value | |
mysqlx_idle_worker_thread_timeout | |
60 | |
0 | |
3600 |
--mysqlx-interactive-timeout=value | |
mysqlx_interactive_timeout | |
28800 | |
1 | |
2147483 |
mysqlx_wait_timeout
--mysqlx-max-allowed-packet=value | |
mysqlx_max_allowed_packet | |
1048576 | |
512 | |
1073741824 |
max_allowed_packet
--mysqlx-min-worker-threads=value | |
mysqlx_min_worker_threads | |
2 | |
1 | |
100 |
--mysqlx-max-connections=value | |
mysqlx_max_connections | |
100 | |
1 | |
65535 |
max_connections
--mysqlx-port=value | |
mysqlx_port | |
33060 | |
1 | |
65535 |
port
--mysqlx-port-open-timeout=value | |
mysqlx_port_open_timeout | |
0 | |
0 | |
100 |
--mysqlx-read-timeout=value | |
mysqlx_read_timeout | |
28800 | |
30 | |
2147483 |
--mysqlx-socket=file_name | |
mysqlx_socket | |
/tmp/mysqlx.sock |
--mysqlx-wait-timeout=value | |
mysqlx_wait_timeout | |
28800 | |
1 | |
2147483 |
mysqlx_wait_timeout
mysqlx_interactive_timeout
--mysqlx-write-timeout=value | |
mysqlx_write_timeout | |
60 | |
1 | |
2147483 |
skip_networking
Mysqlx_stmt_create_collection_index
Mysqlx_stmt_drop_collection_index
mysqlx
--skip-networking
Mysqlx_connection_accept_errors
Mysqlx_ssl_accept_renegotiates