---
title: "MySQL汉字字段按拼音排序和备份"
author: "tiroc"
date: "2010-09-18T11:41:55Z"
tags: ["MySQL", "备份", "排序", "用户"]
categories: ["数据库"]
slug: "mysql"
draft: false
lastmod: "2014-04-22T11:34:30Z"
id: 766430
url: "https://tiroc.iteye.com/blog/766430"
---

UTF-8编码的数据库，如果希望汉字字段按照拼音排序：

```
SELECT * FROM students ORDER BY CONVERT( name USING gbk ) ;
```

 原文地址：[http://blog.csdn.net/stephenxu111/archive/2009/08/11/4436181.aspx](http://blog.csdn.net/stephenxu111/archive/2009/08/11/4436181.aspx)

 

 

数据库备份：

 

```
#mysqldump最常用于备份一个整个的数据库：

shell> mysqldump -u username -p --opt db_name > backup-file.sql

#你可以这样将转储文件读回到服务器：

shell> mysql -u username -p db_name < backup-file.sql
```

 

 [mysqldump 只导出数据 或者 只导出表结构](http://hlee.iteye.com/blog/366540)

 

创建用户：

 

```
CREATE USER 'username'@'localhost' IDENTIFIED BY 'password';
```

  

为用户分配访问权限：

 

```
GRANT ALL ON database_name.* TO 'username'@'localhost';
```

 

查看用户权限：

 

```
show grants;
show grants for username;
show grants for username@localhost;
```

 

修改用户密码：

 

```
set password for username@’localhost’ = password(‘newpassword’); 
flush privileges;
```

取消用户授权：

 

```
revoke all on *.* from sss@localhost ;
```

 

删除用户：

 

```
use mysql
delete from user where user='name' and host='localhost' ;
flush privileges ;
```