RMySQL基本操作:
下面列出 RMySQL 的基本操作,基本上都会列出相应的SQL语句:
注意以 “mysql> ” 开头的就是对应的SQL语句
1、连接数据库
> con <- dbConnect(MySQL(), user="root", password="", dbname="test", host="localhost.localdomain")
//相当与SQL
[root@localhost pubuser1]# mysql -u root -p
Enter password:
mysql> use test
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
2、查看数据库基本信息
查看所有的表:
> dbListTables(con)
[1] "t_user"
mysql> show tables;
+----------------+
| Tables_in_test |
+----------------+
| t_user |
+----------------+
1 row in set (0.00 sec)
查询表中的所有字段:
> dbListFields(con, "t_user")
[1] "id" "user"
mysql> select column_name from information_schema.columns where table_schema='test';
+-------------+
| column_name |
+-------------+
| id |
| user |
+-------------+
待续。。。。。。