MySQL官网下载:https://dev.mysql.com/downloads/mysql/
注:在5.7之后MySQL不在生成my-default.cnf配置。
tar -xzvf mysql-5.7.28-linux-glibc2.12-x86_64.tar.gz
mv mysql-5.7.28-linux-glibc2.12-x86_64.tar.gz/ /usr/local/mysql
新建 useradd mysql
新建文件夹
mkdir /usr/local/mysql/data
生成配置:
./mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
./mysql_ssl_rsa_setup --datadir=/usr/local/mysql/data
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
生成初始密码:Yv;fdhxjJ5.u
启动:
bin/mysqld_safe --user=mysql &
service mysqld start
查看启动情况:
systemctl status mysqld
service mysqld status
开机启动:
chkconfig --add mysqld
//查看开机启动項
chkconfig --list
删除开机启动:
chkconfig --del mysqld
MySQL启动成功:
关闭MySQL:service mysqld stop
配置MySQL的环境变量:
export JAVA_HOME=/home/app/app/soft/java export MYSQL_HOME=/usr/local/mysql PATH=$PATH:$HOME/bin:$JAVA_HOME/bin:$MYSQL_HOME/bin: export PATH
刷新source ~/.bash_profile,环境变量配置完成后,可以在任意目录执行打开MySQL:mysql -u root -p