一:安装mysql
1:下载mysql
[root@ghs src]#
wget http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.35-linux-glibc2.5-i686.tar.gz
2:解压
[root@ghs ~]#
tar -zxvf mysql-5.6.35-linux-glibc2.5-i686.tar.gz
3:将解压的Mysql包移动
[root@ghs ~]#
mv mysql-5.6.35-linux-glibc2.5-i686 /usr/local/mysql
4:创建Mysql用户和数据库存放目录
[root@ghs ~]#
mkdir /data/mysql
[root@ghs ~]#
useradd -s /sbin/nologin mysql
5:切换到解压的文件里,初始化指定mysql用户和datadir目录
[root@ghs ~]#
cd /usr/local/mysql/
[root@ghs mysql]#
./scripts/mysql_install_db --user=mysql --datadir=/data/mysql
初始化出现下面错误
error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
缺少安装包libaio和libaio-devel.
解决方法:命令
yum install -y libaio libaio-devel
6:拷贝mysql配置文件
[root@ghs mysql]#
cp support-files/my-large.cnf /etc/my.cnf
7:拷贝启动脚本文件并修改其属性
[root@ghs mysql]#
cp support-files/mysql.server /etc/init.d/mysqld
[root@ghs mysql]#
chmod 755 /etc/init.d/mysqld
8:修改启动脚本
[root@ghs mysql]#
vim /etc/init.d/mysqld
需要修改的地方有 “
datadir=/data/mysql” (前面初始化数据库时定义的目录)
9:把启动脚本加入系统服务项,并设定开机启动,启动mysql
[root@ghs mysql]#
chkconfig --add mysqld
[root@ghs mysql]#
chkconfig mysqld on
[root@ghs mysql]#
service mysqld start
如果启动不了,请到 /data/mysql/ 下查看错误日志,这个日志通常是主机名.err.
9:ps检查mysql是否启动
[root@ghs mysql]#
ps aux |grep mysqld