问: 假如密码中包含反斜线,该如何处理呢?
答: 在mysql中,反斜线\是有特殊意义的,用于转义,因此假如密码中包含\,就须要特别留心。有一种一劳永逸的方法,就是在密码中不用反斜线,哈哈。另一种,那就是须要多加多个反斜线,例如:
(root:hostname:thu oct 15 09:15:38 2009)[mysql]> grant usage on *.* to yejr@localhost identified by 'ye\\\jr';
query ok, 0 rows affected (0.02 sec)
(root::thu oct 15 09:16:22 2009)[mysql]> select password('ye\jr');
+-------------------------------------------+
password('ye\jr')
+-------------------------------------------+
*9db91006131e32b22135599033c6a9c196ec3c6b
+-------------------------------------------+
1 row in set (0.00 sec)
(root::thu oct 15 09:23:32 2009)[mysql]> select host,user,password from user where user='yejr';
+-----------+------+-------------------------------------------+
hostuserpassword
+-----------+------+-------------------------------------------+
localhostyejr*f06d79d5f57894772b64bf3164abb714ebdbd3e2
+-----------+------+-------------------------------------------+
1 row in set (0.01 sec)
(root::thu oct 15 09:16:28 2009)[mysql]> select password('ye\\\jr');
+-------------------------------------------+
password('ye\\\jr')
+-------------------------------------------+
*f06d79d5f57894772b64bf3164abb714ebdbd3e2
+-------------------------------------------+
1 row in set (0.01 sec)
[@tc_10.11.54.224_cnc ~]# mysql -uyejr -p'ye\jr'
logging to file '/home/mysql/query.log'
welcome to the mysql monitor. commands end with ; or \g.
your mysql connection id is 63
server version: 5.x.x-percona-highperf-x-log mysql percona high performance edition (gpl)
type 'help;' or '\h' for help. type '\c' to clear the current input statement.
(yejr::thu oct 15 09:24:58 2009)[(none)]> bye
从上面的例子可以看到,假如密码中有反斜线,就须要在它前面再加2个反斜线。
