MYSQL管理
RPM方式
启动和关闭
service mysql start或
/etc/rc.d/init.d/mysql start或
mysqld_safe&或
safe_mysqld&
service mysql stop
/etc/rc.d/init.d/mysql stop
mysqladmin shutdown
测试
ping
mysqladmin ping
mysqladmin version
系统数据库mysql与测试数据库test
mysqlshow
++++++++++++++++++++++++++++++++
add a user
username billy passwd:123
在任何主机%登录,并对所有的数据库*.*有下面这些权限
mysql>grant select,insert,update,delete on *.* to by '123'
###############
msyql -u root -p
123456
mysql>
################
只可以在localhost上登录,不可以通过WEB
mysql>grant select,insert,update,delete on *.* to identified by '123'
创建一个admin passwd:123
grant all [privileges] on *.* to identified by '123' with grant option;
use msyql
select * form mysql.user;
============================
revoke all on *.* form billy
revoke all on *.* from ;
delete from user where user='billy';
#flush privileges; //不会立马生效,要刷新一下
删除匿名用户
delete from user where host='localhost' and user=''
#flush privileges; //刷新内存授权表
exit
==========================
msyqladmin -u用户名 -p旧密码 password 新密码
或
mysql>set password for root=password("1234556");
set password=password('1234556') ;
我的加了密码mysql
msyql>update user set password=password('1234556')
>where user='root';
>flush privileges;
清除密码
mysqladmin -uroot -p1234556 password ''
1
mysqladmin -uroot -p123456 password mysql
[ven@armohost bin]$ mysql -uroot -p
Enter password:
mysql>
但对于普通用户
mysqladmin -ubilly -p123 password 12345
mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user (using password: YES)'
删除那条 user 为 空、host 为 localhost 的记录。你新添加的记录被它匹配了,根本匹配不到,还真的对了
呵呵
还有对于普通用户
vi ~/.bachrc //有可能是profile等文件
把PATH=" "
加进去,然后执行
source ~/.bachrc
就可以使用某些原来不能使用的命令
=================================
mysql表的优化
对表做一些碎片整理及数据统计
msyql>optimize table table1,table2,... ...
对含有varchar,blob,text列的表,记录长度可变的,有用
===================================
备份和恢复
导出和导入
vi stu.txt
3 billy wuhandaxue 1982-01-02
4 ven wuhandaxue 1979-02-01
之间用TAB分开
mysql school
mysql>load data infile '/tmp/stu.txt' into table stu;
或
mysqlinport school /tmp/stu.txt
===============
===============
备份
eg1:把db school中的表全部备份到school_2004_9.sql文本文件
msyqldump --opt school > school_2004_9.sql
操作目录为当前目录
vi school_2004_9.sql
eg2:把db school中的表teacher,student这二个表备份到school_teacher_sutdent_2004_9.sql文本文件
msyqldump --opt school teacher student > school_teacher_sutdent_2004_9.sql
eg3:备份多个db
mysqldump --databases school test > school_test_2004_9.sql
================
================
恢复
假如把数据库删除了
create databases school;
use school;
source school_2004_9.sql; #恢复
只是粗略地把MYSQL部分看了一下,因为本人想学PHP了,所以对MYSQL暂时先到这里了,有什么不正确还请各位指点哦
email:billy at arhost.namliong.com.tw (at 换 @)
THE END
阅读(2248) | 评论(0) | 转发(0) |