第一步:创建用户和组
#Groupadd oinstall
#useradd mysql -g oinstall -d /home/mysql
#cd /home/mysql
第二步:下载Mysql文件mysql-5.7.12-linux-glibc2.5-x86_64.tar.gz
上传到/home/mysql目录
##tar -xvf mysql-5.7.12-linux-glibc2.5-x86_64.tar.gz
重命名文件
#mv mysql-5.7.12-linux-glibc2.5-x86_64 mysql5.7.12
进入文件夹
#cd mysql5.7.12
创建数据库目录
#cd mkdir data
赋予用户文件夹权限
#chown -R mysql:oinstall /home/mysql/mysql5.7.12
切换用户
#su mysql
更改目录使用权限
#chmod -R 777 /home/mysql/mysql5.7.12
第三步:安装mysql
更改mysql默认配置文件
Vi /etc/my.cnf
Basedir=/home/mysql/mysql5.7.12
Datadir=/home/mysql/mysql5.7.12/data
进入mysql的bin目录
#Cd mysql/bin
执行安装和初始化
#./mysqld --initialize --user=mysql --basedir=/home/mysql/mysql5.7.12 --datadir= /home/mysql/mysql5.7.12/data
显示如下信息
2020-11-05T10:07:30.563460Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2020-11-05T10:07:31.351210Z 0 [Warning] InnoDB: New log files created, LSN=45790
2020-11-05T10:07:31.458145Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2020-11-05T10:07:31.531409Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: b7bac83a-1f4e-11eb-aa3e-0800271eb471.
2020-11-05T10:07:31.532997Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2020-11-05T10:07:31.541310Z 1 [Note] A temporary password is generated for root@localhost: 5Oe>NFILGsDp
最后一行是密码,记住!!5Oe>NFILGsDp
第四步:设置mysql连接
使用刚才生成的密码登录
mysql -u root
Password:输入密码后进入mysql命令行设置密码
Mysql > set password for root@localhost=password('你的密码');
开启远程连接
Mysql > grant all privileges on *.* to 'root'@'%' IDENTIFIED By '密码' with grant option;
开启防火墙端口3306
#/sbin/iptables -I INPUT -p tcp --dport 3306 -j ACCEPT
#/etc/rc.d/init.d/iptables save
因篇幅问题不能全部显示,请点此查看更多更全内容