yum--enablerepo=remi update mysql mysql-server mysql-devel
一定要注意,将mysql服务设置为开机自启动:
chkconfigmysqld on 1.2 密码设置与用户授权 1.2.1 root密码设置
1. shell命令行:mysqladmin -uroot -ppassword 'new_password'
2. mysql命令行:upload mysql.user set password=password("new_passwd")where user="root" and host="localhost"; 1.3 账号授权
1. 账号授权:grant all privileges on *.* to user_name@'%' identified by '1234';
2. 权限回收:revoke GRANT ALL PRIVILEGESON *.* from 'user_name'@'%';
这个只属于新手用的命令,更详细的会在下文中详细介绍 2 mysql使用技巧 2.1 中文乱码 1. 首先进入mysql命令行看下mysql使用什么编码方式:
showvariables like "%char%";2. 在命令行零时修改mysql编码方式:
SETcharacter_set_client='utf8';
SETcharacter_set_connection='utf8';
binlog-format=mixed #二进制格式 mixed[由系统根据语句决定]/row[2进制记录磁盘变化]/statement[2进制记录执行语句]
授权:
grant replication client,replication slaveon *.*
to'repl'@'192.168.85.%' identified by 'repl';
flush privileges; 2. 配置从服务器
vi /etc/my.cnf
server-id=2
log-bin=mysql-bin
binlog-format=mixed
relay-log=mysql-relay #从服务器自己产生日志 3. 授权从服务器
change master to
master_host='192.168.85.111',
master_user='repl',
master_password='repl',
master_log_file='mysql-bin.000001',
master_log_pos=98;
start slave;
show master status;
show slave status;
reset master;
reset slave; 2.9 mysql权限 2.9.1 授权实例
create temporary tables 创建零时表权限
show view 查看视图
本文实例,运行于 MySQL5.0 及以上版本。
MySQL 赋予用户权限命令的简单格式可概括为:
grant 权限 on 数据库对象 to 用户 1. 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 ontestdb.* to common_user@'%' 2. grant 数据库开发人员,创建表、索引、视图、存储过程、函数。。。等权限。
grant 创建、修改、删除 MySQL 数据表结构权限。
grant create on testdb.* todeveloper@'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.* todeveloper@'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.* todeveloper@'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.%'; 3. grant 普通 DBA 管理某个 MySQL 数据库的权限。
grant all privileges on testdb todba@'localhost' 其中,关键字 “privileges” 可以省略。 4. grant 高级 DBA 管理 MySQL 中所有数据库的权限。
grant all on *.* to dba@'localhost'5. MySQL grant 权限,分别可以作用在多个层次上。 6. grant 作用在整个 MySQL 服务器上:
grant select on *.* to dba@localhost; --dba 可以查询 MySQL 中所有数据库中的表。
grant all on *.* to dba@localhost; -- dba 可以管理 MySQL 中的所有数据库
1) grant 作用在单个数据库上:
grant select on testdb.* to dba@localhost;-- dba 可以查询 testdb 中的表。
2) grant 作用在单个数据表上:
grant select, insert, update, delete ontestdb.orders to dba@localhost;
3) grant 作用在表中的列上:
grant select(id, se, rank) ontestdb.apache_log to dba@localhost;
4) grant 作用在存储过程、函数上:
grant execute on procedure testdb.pr_add to'dba'@'localhost'
grant execute on function testdb.fn_add to 'dba'@'localhost' 7. 查看 MySQL 用户权限
查看当前用户(自己)权限:
show grants;
查看其他 MySQL 用户权限:
show grants for dba@localhost; 8. 撤销已经赋予给 MySQL 用户权限的权限。
revoke 跟 grant 的语法差不多,只需要把关键字“to”换成 “from” 即可:
grant all on *.* to dba@localhost;
revoke all on *.* from dba@localhost; 9. MySQL grant、revoke 用户权限注意事项 1) 1. grant, revoke 用户权限后,该用户只有重新连接 MySQL 数据库,权限才能生效。
2. 如果想让授权的用户,也可以将这些权限 grant 给其他用户,需要选项 “grant option“
grant select on testdb.* to dba@localhostwith grant option; 这个特性一般用不到。实际中,数据库权限最好由 DBA 来统一管理。
#查看grant添加的用户:selectuser,host from mysql.user;
#删除用户:
mysql> drop user"tongor"@localhost; 2.10 mysql存储过程权限
即时赋予一个用户,执行存储过程的权限,普通用户执行非他自己创建的存储过程还是会失败
execute command denied to user'test_ryd'@'%' for routine 'test_04.generate_serialno'
The user specified as a definer('user_admin'@'%') does not exist
但是提示存储过程定义中的definer不存在,原来仅仅是连接到MySQL服务器的用户具有执行存储过程的权限是远远不够的,最终要通过存储过程定义中指定的definer来执行存储过程。 3 mysql排错 3.1 msyql.proc is wrong
解决:mysql_upgrade -u root -p
知识:mysql_upgrade升级授权表 3.2 ERROR 2006 (HY000) at line1: MySQL server has gone away
解决:SQL语句过长,建议改语句
知识:insert执行语句过长造成的 3.3 Cannot load frommysql.proc. The table is probably corrupted
【错误过程】:MySQL从5.1升级至5.5后在调用存储过程时报出“Cannotload from mysql.proc. The table is probably corrupted。”
【造成原因】:MySQL升级完成后未对相关数据库执行升级.
【解决办法】:在命令行中执行mysql_upgrade-uroot -p 即可~ 3.4 mysql max_allowed_packet
showVARIABLES like '%max_allowed_packet%';