1.创建库
CREATE DATABASE IF NOT EXISTS yourdbname DEFAULT CHARSET utf8 COLLATE utf8_general_ci;
删除数据库
DROP DATABASE [ IF EXISTS ] <数据库名>
2.分组查询并取分组的某一个值(表中有时间字段)
SELECT i.name,hy.value FROM items i LEFT JOIN history_uint hy ON i.itemid=hy.itemid
where hostid=100086 and i.key_ like "db2.tablespaces.used.pages%" and clock in (SELECT max(hy.clock) FROM items i LEFT JOIN history_uint hy ON i.itemid=hy.itemid
where hostid=10086 and hy.clock <= 1551860333 and i.key_ like "db2.tablespaces.used.pages%" GROUP BY i.name);
3.mysql时间戳字段以日期格式显示
select id,FROM_UNIXTIME(clock,'%Y-%m-%d %H:%i:%s') from tb
where id = 36436;
4.mysql重启
方式一:sudo /etc/init.d/mysql start
方式二:sudo service mysql start
停止mysql:
方式一:sudo /etc/init.d/mysql stop
方式二:sudo service mysql stop
重启mysql:
方式一:sudo/etc/init.d/mysql restart
方式二:sudo service mysql restart
5.设置外部访问
进入mysql
查看user表,字段host的值 应该是 %
>use mysql;
>select user,host from user;
...
设置外部访问
>update user set host = '%' where user ='root';
>flush privileges;
>quit;
#去修改mysql配置文件,查看配置文件位置
$ mysqld --help --verbose | less
...
Default options are read from the following files in the given order:
/etc/my.cnf /etc/mysql/my.cnf ~/.my.cnf
....
注释my.cnf 文件中的bind-address=127.0.0.1
#bind-address=127.0.0.1
查看mysql 可访问的ip
$netstat -an|grep 3306
如下图 :::3306 表示可以外部连接
6.导入.sql文件
1.创建库
2.进入库
>.use 库名
3.导入文件
>source sql文件的路径
4.验证
>show tablses;
后续…