#!/bin/bash
USER="zend"
PASSWORD=""
#OUTPUT="/Users/rabino/DBs"#rm "$OUTPUTDIR/*gz" > /dev/null 2>&1
databases=`mysql -u $USER -p$PASSWORD -e "SHOW DATABASES;" | tr -d "| " | grep -v Database`
MySQL
1. 运行SQL语句授权用户
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'password'
2. 编辑/etc/mysql/my.cnf,把bind-address = 127.0.0.1
注释掉
3. 重启MySQL服务
service mysql restart
如果用户还需要拥有授权其他用户的权限,则需要用下面的命令(把%换成IP),用户要退出重新登录mysql才能生效:
SELECT * FROM
(
SELECT *, MAX(field) AS max_field
FROM mytable
GROUP BY field_id
) t
ORDER BY max_field
其中,field,field_id应替换成具体的列名,mytable替换成具体的表名
用FROM_UNIXTIME函数转换,例如:
SELECT FROM_UNIXTIME(int_time_column) FROM table
通常,MySQL导出导入数据通过mysqldump完成就够了,--where参数也能够选择导出部分数据。但有些情况下,我们需要对数据做些加工,比如增加一个ID字段再导入(把多个站点的数据汇总统计),那么原生的SQL语句就不好处理。CSV格式会是不错的选择。
导出语句:
SELECT *
FROM mytable
WHERE 1
INTO OUTFILE '/tmp/t.csv'
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n';
导入语句:
LOAD DATA INFILE '/tmp/t.csv'
INTO TABLE mytable
CHARACTER SET 'utf8'
FIELDS TERMINATED BY ',' ENCLOSED BY '"'
LINES TERMINATED BY ‘\n’;
然而,这个方法需要需要赋予数据库用户文件的权限(GRANT FILE ON *.* TO 'user'@'localhost';),这个权限通常不是默认有的。
热门内容
最新内容
- 18 hours ago
- 19 hours ago
- 3 days 18 hours ago
- 3 days 18 hours ago
- 3 days 18 hours ago
- 3 days 18 hours ago
- 4 days 19 hours ago
- 3 weeks ago
- 1 month ago
- 1 month ago
最新评论