接下来。装逼开始....
mysql插入数据
语法:
INSERT INTO table_name ( field1, field2,...fieldN )
VALUES
( value1, value2,...valueN );
INSERT INTO test_user (NAME, mobile, address)
VALUES
(
'张三三',
18847474549,
'浙江杭州'
)
以values分割,上面的括号里面是数据库中的字段名称;下面括号的字段是对相应字段的值
示例1:通过命令行插入数据
root@7c6316b19d80:/# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 66
Server version: 5.6.51 MySQL Community Server (GPL)
mysql> sue testing;
Database changed
mysql> insert into test_user(name, mobile, address) values ('python', 18856565858, 'Hangzhou');
Query OK, 1 row affected (0.00 sec)
mysql> insert into test_user(name, mobile, address) values ('java', 17756565858, 'Hangzhou');
Query OK, 1 row affected (0.00 sec)
mysql> insert into test_user(name, mobile, address) values ('php', 15556565858, 'Hangzhou');
Query OK, 1 row affected (0.01 sec)
mysql> insert into test_user(name, mobile, address)
-> values
-> ('c#', 17748484142, 'Hangzhou');
Query OK, 1 row affected (0.00 sec)
注意点:
往数据库中插入了四条数据,均没添加id字段,是因为id设置了自增属性(AUTO_INCREMENT)
“ - > ” 是换行操作,sql语句很长时回车换行输入,切记回车别加分号,不然就直接执行了...
示例2:使用python脚本插入数据
import pymysql
# 连接数据库
conn = pymysql.connect(host="8.136.250.157", user="root", password="123456",
database="testing", port=3306, charset=&