CentOS6.8下安装MySQL5.6

时间:2022-12-02 05:05:35

一:卸载旧版本

使用下面的命令检查是否安装有MySQL Server

rpm -qa | grep mysql

有的话通过下面的命令来卸载掉

rpm -e mysql             //普通删除模式
rpm -e --nodeps mysql // 强力删除模式,如果使用上面命令删除时,提示有依赖的其它文件,则用该命令可以对其进行强力删除

二:安装MySQL

安装编译代码需要的包

yum -y install make gcc-c++ cmake bison-devel  ncurses-devel

下载MySQL-5.6.35

#wget https://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz
#tar xvf mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz
#mv mysql-5.6.35-linux-glibc2.5-x86_64 /usr/local/mysql

创建mysql用户和组

#groupadd mysql
#useradd -r -g mysql mysql -d /usr/local/mysql
#echo "mima" | passwd --stdin mysql

修改目录权限

chown -R mysql:mysql /usr/local/mysql

安装数据库

#su - mysql
#/usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
#exit

复制mysql配置文件

#cd /usr/local/mysql/support-files
#cp my-default.cnf /etc/my.cnf

添加系统服务

#cp mysql.server /etc/init.d/mysql
#chkconfig mysql on

.添加环境变量

#vim /etc/profile
export MYSQL_HOME="/usr/local/mysql"
export PATH="$PATH:$MYSQL_HOME/bin"
#source /etc/profile

启动mysql

service mysql start

设置root密码

mysqladmin -u root password '123456'

设置默认端口

#vim /etc/my.cnf
[mysqld]
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
port=3306
server_id=1
socket=/tmp/mysql.sock

允许所有外部链接访问(可选)

#mysql -u root -p
#mysql命令行输入
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
FLUSH PRIVILEGES;

使用yum快速 安装MySQL数据库

1.查看CentOS下是否已安装mysql
[root@localhost ~]# yum list installed | grep mysql 2.删除已安装mysql
[root@localhost ~]# yum -y remove mysql 3.查看yum库中的mysql(非必须)
[root@localhost ~]# yum list | grep mysql 4.从yum库中的安装mysql
[root@localhost ~]# yum -y install mysql mysql-server mysql-devel 5.验证是否安装成功
[root@localhost ~]# rpm -qi mysql-server 6.启动MySql服务
[root@localhost ~]# /etc/init.d/mysqld start 7.登录并设置密码
[root@localhost ~]# mysql -u root
mysql> show databases;
mysql> use mysql;
mysql> update user set password=password('123456') where user='root'; 8.开放远程登录权限
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
Query OK, 0 rows affected (0.00 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec) 9.设置开机启动(非必须)
chkconfig mysqld on

参考文档:

    http://www.cnblogs.com/liuyi2614/p/6382183.html 

    http://blog.csdn.net/jeffleo/article/details/53559712?utm_source=itdadao&utm_medium=referral