转载请出自出处:http://eksliang.iteye.com/blog/2298702
一、检查MySQL及相关RPM包,是否安装,如果有安装,则移除
[root@Mast ~]# rpm -qa | grep -i mysql mysql-libs-5.1.66-2.el6_3.x86_64 #卸载的时候可能存在依赖包,直接 -ev还删除不掉,需加上--nodeps 强制删除 [root@Mast ~]# rpm -ev mysql-libs-5.1.66-2.el6_3.x86_64 error: Failed dependencies: libmysqlclient.so.16()(64bit) is needed by (installed) postfix-2:2.6.6-2.2.el6_1.x86_64 libmysqlclient.so.16(libmysqlclient_16)(64bit) is needed by (installed) postfix-2:2.6.6-2.2.el6_1.x86_64 mysql-libs is needed by (installed) postfix-2:2.6.6-2.2.el6_1.x86_64 [root@Mast ~]# rpm -ev mysql-libs-5.1.66-2.el6_3.x86_64 --nodeps
二、下载Linux对应的RPM包
官方下载地址:http://dev.mysql.com/downloads/mysql/ 选择MySql Community Service(社区版进行下载)
我的是centos6.5 x86的系统,所以的下载包如下所示
[root@Mast data]# uname -a Linux Mast 2.6.32-358.el6.x86_64 #1 SMP Fri Feb 22 00:31:26 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux [root@Mast data]# ls -l total 115360 -rw-r--r--. 1 root root 23495271 MySQL-client-5.6.30-1.linux_glibc2.5.x86_64.rpm -rw-r--r--. 1 root root 4591071 MySQL-devel-5.6.30-1.linux_glibc2.5.x86_64.rpm -rw-r--r--. 1 root root 90037444 MySQL-server-5.6.30-1.linux_glibc2.5.x86_64.rpm
三、安装MySQL
[root@Mast data]# rpm -ivh MySQL-server-5.6.30-1.linux_glibc2.5.x86_64.rpm [root@Mast data]# rpm -ivh MySQL-devel-5.6.30-1.linux_glibc2.5.x86_64.rpm [root@Mast data]# rpm -ivh MySQL-client-5.6.30-1.linux_glibc2.5.x86_64.rpm
四、初始化MySQL及设置密码
[root@Mast ~]# /usr/bin/mysql_install_db #初始化数据库 [root@Mast ~]# service mysql start #启动数据库 [root@Mast ~]# cat /root/.mysql_secret #查看root用户的初始密码 # The random password set for the root user at Mon May 16 19:31:48 2016 (local time): DXaM9aqT62DxVUcv [root@localhost ~]# mysql -uroot –p mysql> SET PASSWORD = PASSWORD('123456'); #设置密码为123456 mysql> exit [root@localhost ~]# mysql -uroot -p
五、允许远程登录
mysql> use mysql; mysql> select host,user,password from user; +-----------------------+------+-------------------------------------------+ 04 | host | user | password | +-----------------------+------+-------------------------------------------+ | localhost | root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 | | localhost.localdomain | root | *1237E2CE819C427B0D8174456DD83C47480D37E8 | | 127.0.0.1 | root | *1237E2CE819C427B0D8174456DD83C47480D37E8 | | ::1 | root | *1237E2CE819C427B0D8174456DD83C47480D37E8 | +-----------------------+------+-------------------------------------------+ mysql> update user set password=password('123456') where user='root'; mysql> update user set host='%' where user='root' and host='localhost'; mysql> flush privileges; mysql> exit
六、设置开机自启动
[root@Mast data]# chkconfig mysql on [root@Mast data]# chkconfig --list mysql mysql 0:off 1:off 2:on 3:on 4:on 5:on 6:off [root@Mast data]#
七、修改字符集
查看linux系统的字符集
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 | /data/mysql-5.6.30/share/charsets/ | +--------------------------+------------------------------------+
可以看到character_set_database和character_set_server的默认字符集还是latin1,配置/etc/my.cnf文件,加入如下代码,重启后,完美解决
[client] default-character-set=utf8 [mysqld] character-set-server=utf8 [mysql] default-character-set=utf8
每个版本的mysql这个文件的默认配置不一定相同,加入原则就是:
在[client] 后面加上default-character-set=utf8
在[mysqld]后面加上character-set-server=utf8
在[mysql]后面加上default-character-set=utf8
八、MySQL的默认安装位置
/var/lib/mysql/ #数据库目录 /usr/share/mysql #配置文件目录 /usr/bin #相关命令目录 /etc/init.d/mysql #启动脚本
参考博客:http://blog.csdn.net/liumm0000/article/details/18841197