参考:centos7下使用mysql离线安装包安装mysql5.7 - cctext - 博客园
步骤一:将mysql安装包上传到/usr/local/下并解压,由于mysql的启动脚本默认是在这个路径下,如果把mysql安装在其它的目录下,需要修改它的启动脚本
cd /usr/local
tar -zxvf mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz -C /usr/local
将解压后的mysql的tar包更改名称为mysql
mv mysql-5.7.26-linux-glibc2.12-x86_64/ mysql
步骤二:查看系统自带的Mariadb并卸载
rpm -qa|grep mariadb
rpm -e --nodeps mariadb-libs-5.5.56-2.el7.x86_64(根据实际情况复制rpm包)
删除/etc目录下的my.cnf(有就删除)
rm /etc/my.cnf
检查mysql是否存在
rpm -qa |grep mysql
步骤三:检查mysql的组和用户是否存在,如无则创建
检查用户和组:
cat /etc/group | grep mysql
cat /etc/passwd | grep mysql
创建用户和组:
groupadd mysql
useradd -g mysql mysql
passwd mysql (输入密码密码设置成123456)
步骤四:将解压后的mysql的安装包更改用户和组为mysql
cd /usr/local
chown -R mysql:mysql mysql/
在mysql文件夹下创建data目录,并修改用户和组的权限都为mysql
cd /usr/local/mysql
mkdir data
chown -R mysql:mysql data
步骤五:在/etc下创建my.cnf文件
cd /usr/local/mysql
vim my.conf
[mysql]
socket=/var/lib/mysql/mysql.sock# set mysql client default chararterdefault-character-set=utf8
[mysqld]
socket=/var/lib/mysql/mysql.sock# set mysql server port
port = 3306 #默认是3306,这里发现3306已经被占用,因此防止这种情况发生,可以避免使用3306mysql默认端口
# set mysql install base dir
basedir=/usr/local/mysql# set the data store dir
datadir=/usr/local/mysql/data# set the number of allow max connnection
max_connections=200# set server charactre default encoding
character-set-server=utf8# the storage enginedefault-storage-engine=INNODB
lower_case_table_names=1
max_allowed_packet=16M
explicit_defaults_for_timestamp=true
[mysql.server]
user=mysql
basedir=/usr/local/mysql
chown -R mysql:mysqsl my.cnf
chmod 777 my.conf
步骤六进入mysql文件夹,安装mysql
cd /usr/local/mysql
bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/
cp ./support-files/mysql.server /etc/init.d/mysqld
chmod a+x /etc/init.d/mysqld
步骤七:配置环境变量
vim /etc/profile
export PATH=$PATH:/usr/local/mysql/bin
source /etc/profile
步骤八:启动mysql
service mysqld start
查看状态:
service mysqld status
步骤九:登录mysql并设置基础环境
获取mysql初始密码:
cat /root/.mysql_secret
登录:
mysql -u root -p (输入刚才查出的密码)
更改密码:
set PASSWORD = PASSWORD('123456');
刷新保存设置:
flush privileges;
设置root用户的远程登录:
grant all on *.* to root@'%' identified by '123456';
flush privileges;
use mysql;
select user,host from user;
delete from user where user='root' and host='localhost';
select user,host from user;
flush privileges;
步骤10:重启mysql
退出
exit;
service mysqld restart
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)