suse安裝配置mysql
Sql代碼
rpm -qa|grep mysql
查看是否安裝過mysql
或者在yast裡面查看是否安裝過mysql 前面有i表示已經安裝
yast-->software--->software Management-->Filters 選擇RPM Groups--》Applications
如果安裝則進行卸載,在yast裡面或者rpm -e mysql命令卸載
Linux代碼
rpm -ivh Mysql-server***.rpm 安裝mysql服務端
rpm -ivh Mysql-client***.rpm 安裝mysql客戶端
Linux代碼
安裝完畢之後 ps -ef|grep mysql查看mysql是否啟動
沒有啟動則 /etc/init.d/mysql start啟動mysql
然後 mysql回車 進入mysql默認沒有密碼
如果需要更改密碼,推出mysql登錄到linux操作命令下
修改root密碼為root:
Sql代碼
mysqladmin -uroot password 'root'
登錄mysql允許遠程登錄:
Sql代碼
grant all privileges on *.* to root@'%' identified by 'root';
flush privileges;
查看mysql開機啟動狀態:
Linux代碼
chkconfig --list|grep mysql
mysql 0:off 1:off 2:on 3:on 4:on 5:on 6:off
3和5為on表示命令行狀態和圖形界面狀態默認mysql是啟動的,不用修改
修改mysql字符集編碼:
登錄mysql查看:
SHOW VARIABLES LIKE 'character%';
SHOW VARIABLES LIKE 'collation%';
mysql> SHOW VARIABLES LIKE 'character%';
+-----------------------------------+-----------------------------------------+
| Variable_name | Value |
+------------------------------------+----------------------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | latin1 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | latin1 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+------------------------------------+-------------------------------------------+
8 rows in set (0.00 sec)
mysql> SHOW VARIABLES LIKE 'collation%';
+--------------------------+-----------------------+
| Variable_name | Value |
+--------------------------+-----------------------+
| collation_connection | utf8_general_ci |
| collation_database | latin1_swedish_ci |
| collation_server | latin1_swedish_ci |
+--------------------------+-----------------------+
3 rows in set (0.00 sec)
為了防止出現亂碼,修改數據庫編碼為UTF-8,拷貝mysql安裝路徑下的my-small.cnf、my-medium.cnf、my-large.cnf和my-huge.cnf中的一個放到/etc/下 並改名為my.cnf
其中拷貝需要按照機器的配置和數據庫連接壓力來,我拷貝的是my-medium.cnf文件,命令為:
cp /usr/share/mysql/my-medium.cnf /etc/my.cnf
編輯my.cnf文件:
vi /etc/my.cnf
在[mysqld]下面增加:
character_set_server = utf8
collation-server=utf8_bin
init_connect='SET NAMES utf8'
在[client]下面增加:
default-character-set = utf8
在[mysql]下面增加:
default-character-set=utf8
保存並退出,然後重啟mysql服務:/etc/init.d/mysql restart或service mysql restart
重啟完畢,登錄mysql,查詢編碼:
mysql> SHOW VARIABLES LIKE 'character%';
+----------------------------------+-----------------------------------+
| Variable_name | Value |
+----------------------------------+-----------------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+----------------------------------+------------------------------------+
8 rows in set (0.00 sec)
mysql> SHOW VARIABLES LIKE 'collation%';
+--------------------------+---------------------+
| Variable_name | Value |
+--------------------------+---------------------+
| collation_connection | utf8_general_ci |
| collation_database | utf8_bin |
| collation_server | utf8_bin |
+--------------------------+---------------------+
3 rows in set (0.01 sec)
至此mysql修改默認編碼修改完畢.