以下步骤运行环境是centos6.5
1、查找以前是否装有mysql
命令:rpm -qa|grep -i mysql
2、删除mysql
删除命令:rpm -e --nodeps 包名
3、删除老版本mysql的开发头文件和库
命令:rm -rf /usr/lib/mysql
4.删除数据文件和配置文件
rm -rf /var/lib/mysql
rm -rf /etc/my.cnf
5.安装mysql
rpm -ivh MySQL-server-5.5.13-1.rhel5.x86_64.rpm (必须装)
rpm -ivh MySQL-client-5.5.13-1.rhel5.x86_64.rpm (必须装)
rpm -ivh MySQL-devel-5.5.13-1.rhel5.x86_64.rpm (不必装)
rpm -ivh MySQL-shared-5.5.13-1.rhel5.x86_64.rpm (不必装)
rpm -ivh MySQL-test-5.5.13-1.rhel5.x86_64.rpm (不必装)
rpm -ivh MySQL-shared-compat-5.5.13-1.rhel5.x86_64.rpm (不必装)
6.启动mysql
service mysql start
7.添加配置文件
cp /usr/share/mysql/my-medium.cnf /etc/my.cnf
8.编辑配置文件
修改/etc/my.cnf 中的设置,
在[client]节点下添加
default-character-set=utf8
在[mysqld]节点下添加
character-set-server=utf8
collation-server=utf8_general_ci
在文件最后,追加以下内容(设置默认数据库类型)
default-storage-engine=INNODB
命令:rpm -qa|grep -i mysql
2、删除mysql
删除命令:rpm -e --nodeps 包名
3、删除老版本mysql的开发头文件和库
命令:rm -rf /usr/lib/mysql
4.删除数据文件和配置文件
rm -rf /var/lib/mysql
rm -rf /etc/my.cnf
5.安装mysql
rpm -ivh MySQL-server-5.5.13-1.rhel5.x86_64.rpm (必须装)
rpm -ivh MySQL-client-5.5.13-1.rhel5.x86_64.rpm (必须装)
rpm -ivh MySQL-devel-5.5.13-1.rhel5.x86_64.rpm (不必装)
rpm -ivh MySQL-shared-5.5.13-1.rhel5.x86_64.rpm (不必装)
rpm -ivh MySQL-test-5.5.13-1.rhel5.x86_64.rpm (不必装)
rpm -ivh MySQL-shared-compat-5.5.13-1.rhel5.x86_64.rpm (不必装)
6.启动mysql
service mysql start
7.添加配置文件
cp /usr/share/mysql/my-medium.cnf /etc/my.cnf
8.编辑配置文件
修改/etc/my.cnf 中的设置,
在[client]节点下添加
default-character-set=utf8
在[mysqld]节点下添加
character-set-server=utf8
collation-server=utf8_general_ci
设置表名不区分大小写
lower_case_table_names=1
允许本地或者远程建立存储函数
log_bin_trust_function_creators = 1
default-storage-engine=INNODB
保存退出:wq
重启mysql服务
service mysql restart
9.给root添加默认密码
/usr/bin/mysqladmin -u root password 123456
10.登录mysql
mysql -uroot -p123456
11.测试是否可以看到数据库
show databases;
12.验证mysql编码
show variables like '%char%';
13.使mysql可以被外网访问
update user set host='%' where user = 'root'
flush privileges;
14.授权用户(解决root用户可能不能在本机登录的情况)
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%’ IDENTIFIED BY '123456' WITH GRANT OPTION;
flush privileges;
GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY '1989229' WITH GRANT OPTION;
FLUSH PRIVILEGES;
重启mysql服务
service mysql restart
9.给root添加默认密码
/usr/bin/mysqladmin -u root password 123456
10.登录mysql
mysql -uroot -p123456
11.测试是否可以看到数据库
show databases;
12.验证mysql编码
show variables like '%char%';
13.使mysql可以被外网访问
update user set host='%' where user = 'root'
flush privileges;
14.授权用户(解决root用户可能不能在本机登录的情况)
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%’ IDENTIFIED BY '123456' WITH GRANT OPTION;
flush privileges;
GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY '1989229' WITH GRANT OPTION;
FLUSH PRIVILEGES;
mysql安装文件见百度云:http://pan.baidu.com/s/1o6ogRhS