CentOS6.8下安装MySQL5.6
一:卸载旧版本
使用下面的命令检查是否安装有MySQL Server
1 | rpm -qa | grep mysql |
有的话通过下面的命令来卸载掉
1 2 | rpm -e mysql //普通删除模式 rpm -e --nodeps mysql // 强力删除模式,如果使用上面命令删除时,提示有依赖的其它文件,则用该命令可以对其进行强力删除 |
二:安装MySQL
安装编译代码需要的包
1 | yum -y install make gcc-c++ cmake bison-devel ncurses-devel |
下载MySQL-5.6.35
1 2 3 | #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用户和组
1 2 3 | #groupadd mysql #useradd -r -g mysql mysql -d /usr/local/mysql #echo "mima" | passwd --stdin mysql |
修改目录权限
1 | chown -R mysql:mysql /usr/local/mysql |
安装数据库
1 2 3 | #su - mysql #/usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data #exit |
复制mysql配置文件
1 2 | #cd /usr/local/mysql/support-files #cp my-default.cnf /etc/my.cnf |
添加系统服务
1 2 | #cp mysql.server /etc/init.d/mysql #chkconfig mysql on |
.添加环境变量
1 2 3 4 | #vim /etc/profile export MYSQL_HOME= "/usr/local/mysql" export PATH= "$PATH:$MYSQL_HOME/bin" #source /etc/profile |
启动mysql
1 | service mysql start |
设置root密码
1 | mysqladmin -u root password '123456' |
设置默认端口
1 2 3 4 5 6 7 | #vim /etc/my.cnf [mysqld] basedir=/usr/local/mysql datadir=/usr/local/mysql/data port=3306 server_id=1 socket=/tmp/mysql.sock |
允许所有外部链接访问(可选)
1 2 3 4 | #mysql -u root -p #mysql命令行输入 GRANT ALL PRIVILEGES ON *.* TO 'root' @ '%' IDENTIFIED BY '123456' WITH GRANT OPTION; FLUSH PRIVILEGES; |
使用yum快速 安装MySQL数据库
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | 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
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步