1 下载mysql
https://cdn.mysql.com//Downloads/MySQL-5.6/mysql-5.6.37-linux-glibc2.12-x86_64.tar.gz
我下载的是mysql 5.6
2.解压它移动到对应目录下
tar -zxvf mysql-5.6.37-linux-glibc2.12-x86_64.tar.gz
cp ./mysql-5.6.37-linux-glibc2.12-x86_64 /usr/local/mysql
创建用户和组
groupadd mysql和useradd -r -g mysql mysq
进入源码目录
cd /usr/local/mysql/mysql-5.6.37-linux-glibc2.12-x86_64
创建data目录存放mysql 数据
mkdir data
修改目录的用户和组
chown -R mysql:mysql .
复制这个文件到init.d目录下
加入开机自启动项
cp support-files/mysql.server /etc/init.d/mysqld
vi /etc/init.d/mysqld
basedir=/usr/local/mysql/mysql-5.6.37-linux-glibc2.12-x86_64
datadir=/usr/local/mysql/mysql-5.6.37-linux-glibc2.12-x86_64/data
初始化mysql
./scripts/mysql_install_db --use=mysql --basedir=/usr/local/mysql/mysql-5.6.37-linux-glibc2.12-x86_64
--datadir=/usr/local/mysql/mysql-5.6.37-linux-glibc2.12-x86_64/data
--defaults-file=/usr/local/mysql/mysql-5.6.37-linux-glibc2.12-x86_64/my.cnf
加入开机自启动项
chkconfig --add mysqld
chkconfig --list mysqld
启动mysql 服务
service mysqld start
查看是否启动成功
netstat -anp|grep mysqld
进入mysql
./bin/mysql -u root
/usr/local/mysql/mysql-5.6.37-linux-glibc2.12-x86_64/bin/mysqladmin -u root password 'new-password'
/usr/local/mysql/mysql-5.6.37-linux-glibc2.12-x86_64/bin/mysqladmin -u root -h skinglzw password 'new-password'