提示:本文操作环境是MariaDB 和Sqlite3。
本文测试环境Sqlite3 安装文件位于 D:\sqlite-tools-win32-x86-3230100 目录。
Sqlite3 创建数据库hello.db.
命令行下输入(hello.db是实例数据库名称)
#切换到sqlite3可执行文件目录D盘
C:\Users\test>D:
D:\>cd sqlite-tools-win32-x86-3230100
D:\sqlite-tools-win32-x86-3230100>sqlite3
SQLite version 3.23.1 2018-04-10 17:39:29
Enter ".help" for usage hints.
Connected to a transient in-memory database.
Use ".open FILENAME" to reopen on a persistent database.
sqlite> .quit
#创建hello.db数据库
D:\sqlite-tools-win32-x86-3230100>sqlite3 hello.db
SQLite version 3.23.1 2018-04-10 17:39:29
Enter ".help" for usage hints.
sqlite>
#注:本地文件需要在创建表或sqlite3退出后生成本地文件。
命令完成同时进入数据库控制台界面。
.databases命令查看数据库信息,本文数据库文件位于C:\Users\Administrator\hello.db。
.databases
创建表A。
create table A(id,name);
根据命令可知sqlite3创建表可以不指定数据类型。当然,语句结束需要有分号,并最好能够在同一行。
查看表。
.tables
Linux MySQL 远程访问控制。
sudo -i切换到root账号,输入命令mysql。
切换到mysql数据库。
mysql>update user set host='172.20.0.0/24' where user='root';
增加172.20.0.0网段访问权限。host可以是网段,主机名或者IP地址。
mysql>select host,user from user;
查询主机和用户权限设置。
mysql>flush privileges;
刷新用户权限。
root@jiangjuan-OptiPlex-390:~# mysql
ERROR 1698 (28000): Access denied for user 'root'@'localhost'
随意修改权限可能导致无法本地访问数据库。解决该问题方法如下。 首先停止数据库服务。
/etc/init.d/mysql stop
本文还涉及到杀死mysql进程问题。 首先通过ps -aux 命令找到mysql 进程ID,本文是12914(1286),请根据实际情况选择。
kill -s 9 12914
kill -s 9 1286
mysql>mysqld_safe –skip-grant-tables &
mysql>mysql
跳过验证过程,重新登录。
mysql>use mysql
mysql>select user,host,password from user where user='root';
查询结果未显示localhost可以登陆。
mysql>update user set host='localhost' where user='root' and host='%';
mysql>flush privileges;
重新授权并重启MySQL服务即可。
mysql>mysql -u root –p
mysql>use mysql;
mysql>update user set host = '%' where user = 'root';
mysql>select host, user from user;
该方法也可以设置任意机器访问数据库。