当前位置: 代码迷 >> MySQL >> mysql惯用管理命令
  详细解决方案

mysql惯用管理命令

热度:344   发布时间:2016-05-05 16:22:50.0
mysql常用管理命令
1. mysql 安装	yum -y install mysql-server	yum -y install php-mysql	vi /etc/my.cnf	[mysqld]	datadir=/var/lib/mysql	socket=/var/lib/mysql/mysql.sock	user=mysql	# Disabling symbolic-links is recommended to prevent assorted security risks	symbolic-links=0	default-character-set=utf8	[mysqld_safe]	log-error=/var/log/mysqld.log	pid-file=/var/run/mysqld/mysqld.pid	chkconfig mysqld on	chkconfig --list mysqld	/etc/rc.d/init.d/mysqld start 初始化mysql	mysqladmin -u root -p password	delete from mysql.user where user=''; 删除匿名用户	flush privileges;  ← 刷新,使以上操作生效 2. 连接mysql   mysql -h 主机地址 -u 用户名 -p 用户密码    mysql -h110.110.110.110 -uroot -pabcd123(注:u与root可以不用加空格,其它也一样)    mysql -uroot -p;   mysql -uroot -pnewpassword;   mysql mydb -uroot -p;   mysql mydb -uroot -pnewp3. 账户设置   use mysql;   delete from User where User="";   update User set Password=PASSWORD('pass') where User='root';4. 添加账户  向user表中添加数据  使用grant  grant all on mydb.* to [email protected] identified by "password" ;  grant usage on *.* to [email protected] identified by "password";  grant select,insert,update on mydb.* to [email protected] identified by "password";  grant update,delete on mydb.TestTable to [email protected] identified by "password";  全局管理权限:	FILE: 在MySQL服务器上读写文件。	PROCESS: 显示或杀死属于其它用户的服务线程。	RELOAD: 重载访问控制表,刷新日志等。	SHUTDOWN: 关闭MySQL服务。	数据库/数据表/数据列权限:	Alter: 修改已存在的数据表(例如增加/删除列)和索引。	Create: 建立新的数据库或数据表。	Delete: 删除表的记录。	Drop: 删除数据表或数据库。	INDEX: 建立或删除索引。	Insert: 增加表的记录。	Select: 显示/搜索表的记录。	Update: 修改表中已存在的记录。  特别的权限:	ALL: 允许做任何事(和root一样)。	USAGE: 只允许登录--其它什么也不允许做。5. 更改密码  mysqladmin -u 用户名 -p 旧密码 password 新密码   mysqladmin -uroot -password ab12 注:因为开始时root没有密码,所以-p旧密码一项就可以省略了。 6. 备份数据库  mysqldump --opt school>school.bbb  导出整个数据库	mysqldump -u 用户名 -p --default-character-set=latin1 数据库名 > 导出的文件名(数据库默认编码是latin1)	mysqldump -u wcnc -p smgp_apps_wcnc > wcnc.sql  导出一个表	mysqldump -u 用户名 -p 数据库名 表名> 导出的文件名	mysqldump -u wcnc -p smgp_apps_wcnc users> wcnc_users.sql  导出一个数据库结构	mysqldump -u wcnc -p -d –add-drop-table smgp_apps_wcnc >d:wcnc_db.sql	-d 没有数据 –add-drop-table 在每个create语句之前增加一个drop table  导入数据库	常用source 命令		进入mysql数据库控制台,		如mysql -u root -p		mysql>use 数据库		然后使用source命令,后面参数为脚本文件(如这里用到的.sql)		mysql>source wcnc_db.sql	使用mysqldump命令		mysqldump -u username -p dbname < filename.sql	使用mysql命令		mysql -u username -p -D dbname < filename.sql 7. 更改表名:	命令:rename table 原表名 to 新表名;	例如:在表MyClass名字更改为YouClass	mysql> rename table MyClass to YouClass;  
  相关解决方案