centos6.5rpm方式安装mysql5.6
1.下载rpm包
http://dev.mysql.com/downloads/mysql/5.6.html#downloads
包名:MySQL-5.6.21-1.linux_glibc2.5.x86_64.rpm-bundle.tar
2.查看系统是否自带了mysql软件包并卸载
rpm -qa|grep -i mysql
rpm -e 软件名 --nodeps
yum -y remove mysql-libs-5.1.61* 卸载较慢
3.安装
cd /usr/local
tar -zxvf MySQL-5.6.21-1.linux_glibc2.5.x86_64.rpm-bundle.tar
rpm –ivh MySQL-shared-5.6.21-1.linux_glibc2.5.x86_64.rpm
rpm –ivh MySQL-client-5.6.21-1.linux_glibc2.5.x86_64.rpm
rpm –ivh MySQL-devel-5.6.21-1.linux_glibc2.5.x86_64.rpm
rpm –ivh MySQL-server-5.6.21-1.linux_glibc2.5.x86_64.rpm
4.配置mysql配置文件
cp /usr/share/mysql/my-default.cnf /etc/my.cnf
vim /etc/my.cnf
[client]
default-character-set=utf8
[mysqld]
character-set-server=utf8
character_set_server=utf8
character_set_client=utf8
collation-server=utf8_general_ci
#linux 下 mysql 安装完后是默认:表名区分大小写,列名不区分大小写; 0 :区分大小写, 1
:不区分大小写
lower_case_table_names=1
# 设置最大连接数,默认为 151 , MySQL 服务器允许的最大连接数 16384
max_connections=1000
[mysql]
default-character-set=utf8
注释sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
4.启动mysql
service mysql restart
5.登录mysql
mysql的安装后会生成一个随机密码在/root/.mysql_sercret
mysql -u root -p 【随机密码】
SET PASSWORD FOR 'root1'@'%' = PASSWORD('你的密码');
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION #赋予任何主机访问数据的权限
FLUSH PRIVILEGES
有可能无法找到mysql的默认密码,此时需要进入安全模式启动并设置密码(然后退出重新登录,设置新的密码)
方法1:
/etc/init.d/mysql stop
mysqld_safe
mysql -u root mysql
mysql> update user set password=password("123456") where user='root';
mysql> SET PASSWORD = PASSWORD('123456');#设置密码
mysql> FLUSH PRIVILEGES;
mysql> quit;
重启mysql
mysql -u root -p
Enter password: 123456
mysql> SET PASSWORD = PASSWORD('123456');#设置密码
mysql> FLUSH PRIVILEGES;
mysql> quit;
方法2:
关闭mysql数据库service mysql stop或kill for mysql
首先kill掉MySQL进程然后在启动mysql的参数中加入
service mysql start --skip-grant-tables
mysql
mysql> update mysql.user set password=password("123456") where user='root';
mysql> FLUSH PRIVILEGES;
mysql> quit
重启mysql:
service mysql restart
mysql -u root -p
Enter password: 123456
mysql>SET PASSWORD = PASSWORD('123456');#设置密码
mysql>FLUSH PRIVILEGES;
mysql>quit;
6.运行此脚本进行生产服务器安全配置
/usr/bin/mysql_sercre_installlation
#Enter current password for root 输入root密码
#Change the root password? 是否修改root的密码
#Remove anonymous users? 是否删除匿名账号
#Disallow root login remotely? 是否取消root用户远程登录
#Remove test database and access to it? 是否删除test库和对test库的访问权限
#Reload privilege tables now? 是否现在刷新授权表使修改生效
网友评论