MySQL安装

MySQL常用的安装包:rpm、源码、二进制免编译

#cd /usr/local/src //进入这个目录下
[root@localhost ~]# cd /usr/local/src

#wget http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz
[root@localhost src]# wget http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz

#tar -zxvf mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz //解压文件

#mv mysql-5.6.35-linux-glibc2.5-x86_64 /usr/local/mysql //将解压后的文件改名字移到/usr/local/mysql目录下

#cd /usr/local/mysql/ //进入/usr/local/mysql目录下

#useradd mysql //创建mysql的用户

#mkdir /data/ //创建/data/目录

#./scripts/mysql_install_db --user=mysql --datadir=/data/mysql //初始化创建一个mysql的数据目录
[root@localhost mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql
FATAL ERROR: please install the following Perl modules before executing ./scripts/mysql_install_db:
Data::Dumper
[root@localhost mysql]# yum list |grep perl |grep -i dumper
perl-Data-Dumper.x86_64 2.145-3.el7 base
perl-Data-Dumper-Concise.noarch 2.020-6.el7 epel
perl-Data-Dumper-Names.noarch 0.03-17.el7 epel
perl-XML-Dumper.noarch 0.81-17.el7 base

#cp support-files/my-default.cnf /etc/my.cnf //拷贝模板配置文件到配置文件

#cp support-files/mysql.server /etc/init.d/mysqld //将启动脚本放到/etc/initd/目录下
#vi /etc/init.d/mysqld //编辑启动脚本
basedir=/usr/local/mysql
datadir=/data/mysql
保存退出

#chkconfig --add mysqld //将mysqld加入启动项里

#service mysqld start //启动mysql服务