作業環境:fedora13 ; mysql5
linux 下修改mysql 密碼格式如下如下 :
mysqladmin -u userName password newPassword
eg:
mysqladmin -u root password mynewpassword;
中文亂碼問題
修改mysql資料庫的設定檔
# vi /etc/my.cnf
在[mysqld]下添加
default-character-set=utf8
若有[client]在[client]下添加
default-character-set=utf8
3. 重啟mysql
# service mysqld restart
4.登入mysql看看修改成功否
# mysql
如果需要使用者名稱和密碼則
# mysql -uroot -proot
mysql> show variables like 'character_set_%';
mysql> show variables like 'collation_%';
注意:如果自己有初始化資料庫的檔案,要確保檔案的編碼的正確性,通過自己的實踐遇到了 在windows上用mysql front 匯出utf8 格式的資料庫 的".sql"檔案,如果直接用記事本開啟複製上面的資訊後粘貼到 命令列,則用web程式顯示出來有可能仍是亂碼。
最好的辦法就是 通過mysql 的命令 匯出 資料庫 ,而後再 匯入
mysql windows 匯出命令 執行個體
C:/Program Files/MySQL/MySQL Server 5.1/bin>mysqldump -uroot -proot test > d:/test.sql
linux mysql 匯入上面的檔案 執行個體
mysql 要匯入的資料庫 < 要到如的檔案名稱
# mysql mysqltestDB < /usr/test.sql
如拒絕訪問,則說明是存取權限問題 參考如下
java.sql.SQLException: null, message from server: "Host 'xxx' is not allowed to connect to this MySQL server":
你想user使用userPassword從任何主機串連到mysql伺服器的話。
GRANT ALL PRIVILEGES ON *.* TO 'user'@'%' IDENTIFIED BY 'userPassword' WITH GRANT OPTION;
如果你想允許使用者user從ip為192.168.1.15的主機串連到mysql伺服器,並使用userPassword作為密碼
GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'192.168.2.15' IDENTIFIED BY 'userPassword' WITH GRANT OPTION;