安装包地址:戳这
提取码:exl7
解压
tar -zxvf mysql-5.7.27-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
重命名
mv /usr/local/mysql-5.7.27-linux-glibc2.12-x86_64/ /usr/local/mysql
进入mysql文件夹,创建文件及文件,依次执行下面的命令
cd /usr/local/mysql
mkdir data
cd data/
mkdir {logs,data,run}
touch run/mysql.pid
touch logs/mysql_error.log
chmod 777 -R .
在mysql目录下创建配置文件my.cnf
cd /usr/local/mysql
vim my.cnf
文件内容
[client]port=3306socket=/usr/local/mysql/data/mysql.sock default_character_set=utf8[mysqld]port=3306socket=/usr/local/mysql/data/mysql.sock user=mysql basedir=/usr/local/mysql datadir=/usr/local/mysql/data/data character_set_server=utf8[mysqld_safe]pid-file=/usr/local/mysql/data/run/mysql.pid log-error=/usr/local/mysql/data/logs/mysql_error.log[mysql]socket=/usr/local/mysql/data/mysql.sock[mysqldump]socket=/usr/local/mysql/data/mysql.sock[mysqladmin]socket=/usr/local/mysql/data/mysql.sock
创建组
groupadd mysql
创建用户
useradd -r -g mysql mysql
修改mysql文件夹下所有文件及目录的所属用户和所属组
cd /usr/local/mysql
chown mysql:mysql -R .
初始化MySQL
cd /usr/local/mysql/bin
./mysqld --defaults-file=/usr/local/mysql/my.cnf --initialize-insecure --user=mysql --datadir=/usr/local/mysql/data/data
将启动脚本放到开机初始化目录
cd /usr/local/mysql/support-files/
cp mysql.server /etc/rc.d/init.d/mysql
添加开机自启MySQL服务
chkconfig --add mysqdl
chkconfig mysql on
启动MySQL服务
service mysql start
如果报错的话,去查看日志/usr/local/mysql/data/logs/mysql_error.log
添加环境变量
vim /etc/profile
export MYSQL_HOME=/usr/local/mysql export PATH=$PATH:$MYSQL_HOME:/bin
使环境变量生效
source /etc/profile
修改MySQL密码
首先登录,初次登录不需要密码,直接回车
mysql -u root -p
执行SQL语句
alter user 'root'@'localhost' identified by 'root';
后面跟的是你要修改的密码
安装完成