1.下载MySQL
http://dev.mysql.com/downloads/mysql/5.6.html#downloads wget http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.33-linux-glibc2.5-x86_64.tar.gz
2.解压:
#解压 tar -zxvf mysql-5.6.33-linux-glibc2.5-x86_64.tar.gz
#复制解压后的mysql目录---拷贝到mysql文件夹下 cp -r mysql-5.6.33-linux-glibc2.5-x86_64 /usr/local/mysql
3.
#添加用户mysql
useradd -s /sbin/nologin mysql
4、安装
cd /usr/local/mysql/ mkdir ./data/mysql chown -R mysql:mysql ./ ./scripts/mysql_install_db --user=mysql --datadir=/usr/local/mysql/data/mysql
如果执行最后一条命令时,有个错误信息
FATAL ERROR: please install the following Perl modules before executing /usr/bin/mysql_install_db:
安装 Perl-Module-Install 即可
yum install -y perl-Module-Install.noarch
cp support-files/mysql.server /etc/init.d/mysqld chmod 755 /etc/init.d/mysqld cp support-files/my-default.cnf /etc/my.cnf cd /usr/local/mysql cd support-files/ ls cp my-default.cnf /etc/my.cnf y vi /etc/init.d/mysqld service mysqld start --启动数据库 chkconfig mysqld on ----开机自启 cd .. ----切换到根目录 ./bin/mysql -u root -----给root用户授权
#修改启动脚本 vi /etc/init.d/mysqld #修改项: basedir=/usr/local/mysql/ datadir=/usr/local/mysql/data/mysql #启动服务 service mysqld start #测试连接 ./mysql/bin/mysql -uroot #加入环境变量,编辑 /etc/profile,这样可以在任何地方用mysql命令了 export PATH=$PATH:/usr/local/mysql//bin source /etc/profile #启动mysql service mysqld start #关闭mysql service mysqld stop #查看运行状态 service mysqld status