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修改默认编码修改完毕.