Linux之Mysql5.6的安装

卸载老版本MySQL

find / -name mysql 
rm -rf 上边查找到的路径,多个路径用空格隔开 
#或者下边一条命令即可 find / -name mysql|xargs rm -rf

或者

 rpm -qa | grep -i mysql

卸载

rpm -ev mysql-libs-5.1.73-7.el6.x86_64

如果有依赖

rpm -ev mysql-libs-5.1.73-7.el6.x86_64 --nodeps 

还失败,尝试以下命令

rpm -e --noscripts mysql-libs-5.1.73-7.el6.x86_64 

1、解压文件:

tar -zxvf mysql-5.6.31-linux-glibc2.5-x86_64.tar.gz

2、删除安装包,重命名解压后的文件

rm -f mysql-5.6.31-linux-glibc2.5-x86_64.tar.gz mv mysql-5.6.31-linux-glibc2.5-x86_64/ mysql
或者复制
cp -r mysql-5.6.27-linux-glibc2.5-x86_64 /usr/local/mysql

3、添加mysql用户组和mysql用户

先检查是否有mysql用户组和mysql用户

groups mysql

若无,则添加;

groupadd mysql
useradd -r -g mysql mysql

4、进入mysql目录更改权限

[root@tyz~]# cd /usr/local/mysql/
[root@tyz mysql]# chown -R mysql:mysql ./

5、执行安装脚本

--------------------------------使用默认即可,不需要修改------------------------------------
修改/etc/my.cnf

[root@tyz mysql]# vim /etc/my.cnf


[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

修改

[root@tyz mysql]# vim /etc/my.cnf   
  
[mysqld]  
datadir=/usr/local/mysql/data  
socket=/tmp/mysql.sock  
user=mysql  
# Disabling symbolic-links is recommended to prevent assorted security risks  
symbolic-links=0  
  
[mysqld_safe]  
log-error=/usr/local/mysql/data/mysqld.log  
pid-file=/usr/local/mysql/data/mysqld.pid  

------------------------------------------不需要修改-------------------------------

可能会出现乱码,进行如下修改

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html

[mysqld]
port=3306
character_set_server=utf8
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M

# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin

# These are commonly set, remove the # and set as required.
# basedir = .....
# datadir = .....
# port = .....
# server_id = .....
# socket = .....

# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M 

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES 

[client]
port=3306
default-character-set=utf8
[root@tyz mysql]# ./scripts/mysql_install_db --user=mysql

安装完之后修改当前目录拥有者为root用户,修改data目录拥有者为mysql

chown -R root:root ./ 
chown -R mysql:mysql data

6、更改mysql密码

启动,如果已启动,使用kill杀掉进程

./support-files/mysql.server start
[root@jt-mtg-db mysql]# ./support-files/mysql.server start
Starting MySQL. ERROR! The server quit without updating PID file (/var/lib/mysql/jt-mtg-db.pid).

出现以上错误,

MySQL启动之后再执行如下命令更改密码:

[root@tyz mysql]# ./bin/mysqladmin -u root -h localhost.localdomain password '123456'
[root@tyz mysql]#./bin/mysql -h127.0.0.1 -uroot –p123456

登录之后,将其他用户的密码也改为123456

mysql> update mysql.user set password=password('123456') where user='root';
mysql>  flush privileges;

7、增加远程登录权限

mysql> grant all privileges on *.* to root@'%' identified by '123456'; 
mysql> flush privileges;

8、将MySQL加入Service系统服务

复制

[root@tyz mysql]# cp support-files/mysql.server /etc/init.d/mysqld 
[root@tyz mysql]# chkconfig --add mysqld 
[root@tyz mysql]# chkconfig mysqld on 
//查看是否成功
[root@tyz mysql]#  chkconfig --list mysqld
mysqld          0:关闭  1:关闭  2:启用  3:启用  4:启用  5:启用  6:关闭
//如果看到mysql的服务,并且3,4,5都是on的话则成功,如果是off,则键入
service mysqld restart  

service mysqld status

验证

重启,执行以下命令验证

netstat -na | grep 3306

你可能感兴趣的:(Linux之Mysql5.6的安装)