六、Centos Oracle-MySQL-8.0单节点搭建(不推荐使用)
八、Centos Percona-Server-5.7.26单节点搭建(推荐生产使用)
九、Centos Percona-Server-5.7.26镜像全量强一致性集群搭建(推荐生产使用)
十、Centos Percona-Server-5.7.26镜像全量弱一致性集群搭建(推荐生产使用)
十四、MyCat 根据某个字段的值分片搭建(推荐生产使用)
show [session|global] status; # 查看数据库所有状态信息(session当前连接,global(全部))
truncate table 表名; # 清空整张表数据
set global max_allowed_packet = 1024*1024; # 加大mysq批量插入的数量insert into table (aa,bb,cc) values(xx,xx,xx),(oo,oo,oo) on duplicate key update # 遇见相同的key修改,没有插入
replace into table (aa,bb,cc) values(xxx,xxx,xxx),(ooo,ooo,ooo),(ccc,ccc,ccc) # 遇见相同的key修改,没有不操作SELECT * FROM information_schema.columns WHERE column_name='job_name'; # 查询所有表包含 job_name 列名
SELECT
CONCAT("ALTER TABLE ",TABLE_SCHEMA,".",TABLE_NAME," MODIFY COLUMN `job_name` VARCHAR(500);")
FROM information_schema.columns
WHERE column_name='job_name'
AND TABLE_SCHEMA != 'zxyreportdb'# mysqldump -u用户名 -p 库名 表名 --where="过滤条件"(不加 --where="过滤条件" 就是导出整张表) > 导出文件所在目录
$ mysqldump -uroot -p test person --where="id=1" > /home/tools/4.txt
#mysql -h数据库所在ip -u用户名 -p -N -e"查询语句" 库名 > 导出文件所在目录
$ mysql -h127.0.0.1 -uroot -p -N -e"select * from person" test > /home/tools/1.txt$ mysql -h127.0.0.1 -P 3306 -uroot -p # 进入MySQL
# 导入 sql 文件数据(注意:这个方案比较慢,原因是sql是一条一条执行的)
$ source /home/tools/4.sql
# 导入数据文件(注意:这种方式导入速度快)
# fields terminated by(字段以什么分割)
# optionally enclosed by(以什么符号括住CHAR、VARCHAR和TEXT等字符型字段)
# lines terminated by(以什么换行)
# fields escaped by(设置转义字符,默认值为反斜线 \)
# ignore lines(可以忽略前n行)
$ load data infile "/data/mysql/user.sql" into table user fields terminated by ',' optionally enclosed by '"' lines terminated by '\n';# 将test_user库的user表改为user1
$ rename table test_user.user to test_user.user1;skip-grant-tables # 跳过用户名密码验证$ service mysqld restart # 重启服务$ mysql # 进入MySQL服务
$ use mysql; # 进入MySQL系统库
# mysql5.x修改root账号密码
$ update user set password = password('Jiang@123') where user = 'root';
# mysql8.x修改密码
$ alter user 'root'@'localhost' identified with mysql_native_password by '@Ji123456';
$ flush privileges; # 刷新权限$ service mysqld restart # 重启服务二七、SQL优化(注意:insert 语句后面加 IGNORE 关键字,如果插入数据违反了唯一约束(比如主键或唯一索引),不会报错,会返回受影响行数 0,建议生产使用,比如要查询用户手机是否存在,我直接插入数据就行了,返回0就说明用户手机已存在。插入语句示例:insert ignore into user(name)values(?))
1,select * from user limit 1000000,10;可优化成:select a.* from user a join(select * from user limit 1000000,10) b on(a.id = b.id);1,varchar字段建议使用前置索引,因为varchar字段长度大于768个字节将不支持索引