删除MySQL 账号

use mysql
delete from user where user='xiewenming';

授权账号密码

GRANT SELECT,INSERT,UPDATE,DELETE  ON ambari.* TO 'ambariuser'@'192.168.251.0/255.255.255.0'  IDENTIFIED BY '898FAG8Aw9uy';
FLUSH PRIVILEGES; GRANT SELECT,INSERT,UPDATE,DELETE ON hive.* TO 'hiveuser'@'192.168.251.0/255.255.255.0' IDENTIFIED BY '999FAG89Awuy';
FLUSH PRIVILEGES;

授权已有账号到主机

GRANT ALL PRIVILEGES ON *.* TO 'hive'@'%';
FLUSH PRIVILEGES;

导入SQL文件

mysql> source /home/xiewenming/cm_checkout_result.sql;
Connection id:
Current database: cms
Query OK, rows affected (0.00 sec)

创建数据库设置字符集

create database hive character set utf8 ; 

导入数据库(windows 的数据文件到linux下面可能会乱码)
1、首先建空数据库
mysql>create database abc;

2、导入数据库
方法一:
(1)选择数据库
mysql>use abc;
(2)设置数据库编码
mysql>set names utf8;
(3)导入数据(注意sql文件的路径)
mysql>source /home/abc/abc.sql;
方法二:
mysql -u用户名 -p密码 数据库名 < 数据库名.sql
#mysql -uabc_f -p abc < abc.sql

今天监控显示mysql主从复制出错了,信息如下:

mysql> show slave status\G;
*************************** . row ***************************
Slave_IO_State:
Master_Host: 192.168.33.230
Master_User: repl
Master_Port:
Connect_Retry:
Master_Log_File: master-bin.
Read_Master_Log_Pos:
Relay_Log_File: ----relay-bin.
Relay_Log_Pos:
Relay_Master_Log_File: master-bin.
Slave_IO_Running: No
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno:
Last_Error:
Skip_Counter:
Exec_Master_Log_Pos:
Relay_Log_Space:
Until_Condition: None
Until_Log_File:
Until_Log_Pos:
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: NULL
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno:
Last_IO_Error: Got fatal error from master when reading data from binary log: 'Client requested master to start replication from position > file size; the first event 'master-bin.' at 202924128, the last event read from './master-bin.' at 4, the last byte read from './master-bin.' at 4.'
Last_SQL_Errno:
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id:
Master_UUID: f7c24af7-a54a-11e6-88b4-525400169c04
Master_Info_File: /Data/mysql/master.info
SQL_Delay:
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it
Master_Retry_Count:
Master_Bind:
Last_IO_Error_Timestamp: ::
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set:
Executed_Gtid_Set:
Auto_Position:
row in set (0.00 sec) ERROR:
No query specified

show slave status\G

在mysql.cnf里面有一句跳过经常出现的错误,但是还是报了1236错误

slave-skip-errors = 1062,1091,1396,1050,1060,1054,1146,1236

尝试stop slave ; start slave 还是没有恢复

然后就照着上面的错误提示更新pos点

mysql> stop slave;
Query OK, 0 rows affected (0.01 sec) mysql> change master to master_log_file='master-bin.000774', master_log_pos=4;
Query OK, 0 rows affected (0.12 sec) mysql> start slave;
Query OK, 0 rows affected (0.00 sec)

然后查看状态就恢复正常了,具体原因再慢慢分析,,,,,,,

有时候还会报下面这个信息

 Last_IO_Error: Got fatal error  from master when reading data from binary log: 'could not find next log; the first event 'mysql-bin.' at 897184977, the last event read from './mysql-bin.' at 1109808979, the last byte read from './mysql-bin.' at 1109808979.'
上面这个错误尝试stop slave ; start slave 就恢复了
user表中host列的值的意义
%              匹配所有主机
localhost    localhost不会被解析成IP地址,直接通过UNIXsocket连接
127.0.0.1      会通过TCP/IP协议连接,并且只能在本机访问;
::1                 ::1就是兼容支持ipv6的,表示同ipv4的127.0.0.1
 
 授权用户有授权权限

GRANT ALL PRIVILEGES ON *.* TO 'admin'@'%' IDENTIFIED BY '99wuy' WITH GRANT OPTION;

grant 普通数据用户,查询、插入、更新、删除 数据库中所有表数据的权利。

grant select on testdb.* to common_user@’%’

grant insert on testdb.* to common_user@’%’

grant update on testdb.* to common_user@’%’

grant delete on testdb.* to common_user@’%’

或者,用一条 MySQL 命令来替代:

grant select, insert, update, delete on testdb.* to common_user@’%’

9>.grant 数据库开发人员,创建表、索引、视图、存储过程、函数。。。等权限。

grant 创建、修改、删除 MySQL 数据表结构权限。

grant create on testdb.* to developer@’192.168.0.%’;

grant alter on testdb.* to developer@’192.168.0.%’;

grant drop on testdb.* to developer@’192.168.0.%’;

grant 操作 MySQL 外键权限。

grant references on testdb.* to developer@’192.168.0.%’;

grant 操作 MySQL 临时表权限。

grant create temporary tables on testdb.* to developer@’192.168.0.%’;

grant 操作 MySQL 索引权限。

grant index on testdb.* to developer@’192.168.0.%’;

grant 操作 MySQL 视图、查看视图源代码 权限。

grant create view on testdb.* to developer@’192.168.0.%’;

grant show view on testdb.* to developer@’192.168.0.%’;

grant 操作 MySQL 存储过程、函数 权限。

grant create routine on testdb.* to developer@’192.168.0.%’; -- now, can show procedure status

grant alter routine on testdb.* to developer@’192.168.0.%’; -- now, you can drop a procedure

grant execute on testdb.* to developer@’192.168.0.%’;

10>.grant 普通 DBA 管理某个 MySQL 数据库的权限。

grant all privileges on testdb to dba@’localhost’

其中,关键字 “privileges” 可以省略。

11>.grant 高级 DBA 管理 MySQL 中所有数据库的权限。

grant all on *.* to dba@’localhost’

12>.MySQL grant 权限,分别可以作用在多个层次上。

1. grant 作用在整个 MySQL 服务器上:

grant select on *.* to dba@localhost; -- dba 可以查询 MySQL 中所有数据库中的表。

grant all on *.* to dba@localhost; -- dba 可以管理 MySQL 中的所有数据库

2. grant 作用在单个数据库上:

grant select on testdb.* to dba@localhost; -- dba 可以查询 testdb 中的表。

3. grant 作用在单个数据表上:

grant select, insert, update, delete on testdb.orders to dba@localhost;

4. grant 作用在表中的列上:

grant select(id, se, rank) on testdb.apache_log to dba@localhost;

5. grant 作用在存储过程、函数上:

grant execute on procedure testdb.pr_add to ’dba’@’localhost’

grant execute on function testdb.fn_add to ’dba’@’localhost’

注意:修改完权限以后 一定要刷新服务,或者重启服务,刷新服务用:FLUSH PRIVILEGES。

 
优化sql语句,添加索引
MariaDB [thrurls]> select * from yourls_url where url="http://2pchat.mo.cool/2pinvite_listen2/BgMJAQECAQ"
-> ;
+----------+-------------------------------------------------------+--------+---------------------+----------------+--------+
| keyword | url | title | timestamp | ip | clicks |
+----------+-------------------------------------------------------+--------+---------------------+----------------+--------+
| y-h-64ax | http://2pchat.mo.cool/2pinvite_listen2/BgMJAQECAQ | Monkey | 2018-11-28 14:10:54 | 54.149.220.216 | 0 |
+----------+-------------------------------------------------------+--------+---------------------+----------------+--------+
row in set (25.47 sec)

explain分析

MariaDB [thrurls]> explain select * from yourls_url where url="http://2pchat.monkey.cool/2pinvite_listen2/BgMJAQECAQ";
+------+-------------+------------+------+---------------+------+---------+------+--------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+------+-------------+------------+------+---------------+------+---------+------+--------+-------------+
| | SIMPLE | yourls_url | ALL | NULL | NULL | NULL | NULL | | Using where |
+------+-------------+------------+------+---------------+------+---------+------+--------+-------------+
row in set (0.00 sec)

添加索引

 ALTER TABLE yourls_url ADD INDEX idx_url (url());

再次查询

MariaDB [thrurls]> select * from yourls_url where url="http://2pchat.monkey.cool/2pinvite_listen2/BgMJAQECAQ";
+----------+-------------------------------------------------------+--------+---------------------+----------------+--------+
| keyword | url | title | timestamp | ip | clicks |
+----------+-------------------------------------------------------+--------+---------------------+----------------+--------+
| y-h-64ax | http://2pchat.monkey.cool/2pinvite_listen2/BgMJAQECAQ | Monkey | 2018-11-28 14:10:54 | 54.149.220.216 | 0 |
+----------+-------------------------------------------------------+--------+---------------------+----------------+--------+
row in set (0.00 sec)

按照时间排序

select * from yourls_url order by timestamp desc limit  ;
 

MySQL日常维护的更多相关文章

  1. MySQL Cluster 日常维护

    在前面几篇文章已经详细介绍了MySQL Cluster的搭建,配置讲解.而且相信大家都掌握了基本用法.现在我们来看看Cluster的日常维护.熟悉日常维护,将有助于工作中更好的管理和使用Cluster ...

  2. mha日常维护命令

    mha日常维护命令 http://m.blog.chinaunix.net/uid-28437434-id-3959021.html?/13033.shtml 1.查看ssh登陆是否成功masterh ...

  3. MHA 日常维护命令集

    MHA 日常维护命令集 1.查看ssh登陆是否成功 masterha_check_ssh --global_conf=/etc/masterha/masterha_default.conf --con ...

  4. Hive的配置详解和日常维护

    Hive的配置详解和日常维护 一.Hive的参数配置详解 1>.mapred.reduce.tasks  默认为-1.指定Hive作业的reduce task个数,如果保留默认值,则Hive 自 ...

  5. ORACLE分区表梳理系列(二)- 分区表日常维护及注意事项(红字需要留意)

    版权声明:本文发布于http://www.cnblogs.com/yumiko/,版权由Yumiko_sunny所有,欢迎转载.转载时,请在文章明显位置注明原文链接.若在未经作者同意的情况下,将本文内 ...

  6. 数据库日常维护-CheckList_01历史Agent Job执行情况检查

    检查Agent Job中日常维护作业或业务作业是否成功,如每天的备份.碎片整理.索引维护.历史备份文件清除等,可利用SSMS工具,通过CDC下面设置好的DB Server List,运行下面脚本一次, ...

  7. MS SQL 日常维护管理常用脚本(二)

    监控数据库运行 下面是整理.收集监控数据库运行的一些常用脚本,也是MS SQL 日常维护管理常用脚本(一)的续集,欢迎大家补充.提意见. 查看数据库登录名信息   Code Snippet SELEC ...

  8. 2.goldengate日常维护命令(转载)

    goldengate日常维护命令 发表于 2013 年 7 月 4 日 由 Asysdba 1.查看进程状态 GGSCI (PONY) 2> info all 2.查看进程详细状态,有助于排错 ...

  9. db2日常维护

    一. DB2日常维护操作 1.数据库的启动.停止.激活 db2 list active databases db2 active db 数据库名 db2start --启动 db2stop [forc ...

随机推荐

  1. oracle导入csv文件

    oracle导入csv文件: 1.建好对应的表和字段: 2.新建test.ctl文件,用记事本编辑写入: load data infile 'e:\TB_KC_SERV.csv' --修改对应的文件路 ...

  2. Centos7.0配置MySQL主从服务器

    主服务器:192.168.186.131 从服务器:192.168.186.133 主从服务器mysql版本尽量保持一致,安装步骤请阅mysql安装步骤 一.修改主服务器配置文件 #   vi /et ...

  3. Java 内省(Introspector)深入理解

    Java 内省(Introspector)深入理解 一些概念: 内省(Introspector) 是Java 语言对 JavaBean 类属性.事件的一种缺省处理方法. JavaBean是一种特殊的类 ...

  4. python学习笔记(二)— 列表(list)

    列表也叫数组,列表定义,使用[]即可:列表里面可以再套列表,一个里面套一个列表,叫二维数组:一个里面套一个列表,里面的列表再套一个列表,这个叫三维数组,套几层就是几维,定义格式如下: list1 = ...

  5. centos7虚拟机克隆

    第一步:克隆 打开VMware,确认已经完成安装配置的centos7虚拟机在关闭状态. 右键点击虚拟机,选择“管理”-“克隆” 原始虚拟机名称为“master”,IP地址为“192.168.80.10 ...

  6. Linux之Redis-redis哨兵集群详解

    1.Sentinel 哨兵 Sentinel(哨兵)是Redis 的高可用性解决方案:由一个或多个Sentinel 实例 组成的Sentinel 系统可以监视任意多个主服务器,以及这些主服务器属下的所 ...

  7. 又一次认识java(四) — 组合、聚合与继承的爱恨情仇

    有人学了继承,认为他是面向对象特点之中的一个,就在全部能用到继承的地方使用继承,而不考虑到底该不该使用,无疑.这是错误的.那么.到底该怎样使用继承呢? java中类与类之间的关系 大部分的刚開始学习的 ...

  8. 前端 javascript 数据类型 字符串

    字符串是由字符组成的数组,但在JavaScript中字符串是不可变的:可以访问字符串任意位置的文本,但是JavaScript并未提供修改已知字符串内容的方法. obj.charAt(n) 返回字符串中 ...

  9. matplotlib绘制饼状图

    源自http://blog.csdn.net/skyli114/article/details/77508430?ticket=ST-41707-PzNbUDGt6R5KYl3TkWDg-passpo ...

  10. mysql5.7 linux安装参考

    安装参考: https://www.cnblogs.com/ianduin/p/7679239.html http://blog.csdn.net/wb96a1007/article/details/ ...