官方資料:http://dev.mysql.com/doc/refman/5.0/en/resetting-permissions.html#resetting-permissions-unix
還有一個值得參考的mysql安裝,與python-mysql安裝博客http://hearrain.com/2011/01/498
據官方文檔說,
For example, if you run the server using the mysql login account, you should log in as mysql before using the instructions. Alternatively, you can log in as root, but in this case you must start mysqld with the --user=mysql option. If you start the server as root without using --user=mysql, the server may create root-owned files in the data directory, such as log files, and these may cause permission-related problems for future server startups.
如果在安裝完mysql後,當你用root登錄的時候,必須加上--user=mysql,否則的話,服務器會自動創建root-owned文件,這些就會導致權限的問題
我之前就是因為直接登錄了,然後root密碼無修改權限,各種無權限
解決的辦法就是
shell> kill `cat /mysql-data-directory/host_name.pid`mysql-data-directory 的路徑一般是 /usr/local/mysql/data下的包含你的電腦名稱的以pid結尾的文件
UPDATE mysql.user SET Password=PASSWORD('MyNewPass') WHERE User='root'; FLUSH PRIVILEGES;結束進程之後,把上面的兩句話放到一個文件中例如update_passwd,該文件在/usr/local/下
shell> mysqld_safe --init-file=/home/me/mysql-init &
然後sudo su進入root權限,進入mysql下bin輸入以上命令,結束後(我的好像沒有結束,就另開了一個terminal),
進入mysql命令行下
UPDATE mysql.user SET Password=PASSWORD('MyNewPass') -> WHERE User='root';
然後再進入就ok了