Linux安装mysql8
-
第一步:解压mysql安装包:
tar -xvf mysql-server-8.0.25.tar.gz -
第二步:更新文件夹名:
mv mysql-server-8.0.25 mysql -
第三步:进入mysql文件夹:
cd mysql,创建data文件夹:mkdir data -
第四步:创建mysql用户组和mysql用户:
groupadd mysql useradd -g mysql mysql -
第五步:改变mysql目录权限:
chown -R mysql.mysql /opt/soft/mysql/ -
第六步:配置my.cnf,进入etc文件夹,替换my.cnf文件
[mysqld] bind-address=0.0.0.0 port=3306 user=mysql basedir=/opt/soft/mysql datadir=/opt/soft/mysql/data socket=/opt/soft/mysql/data/mysql.sock # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 # Settings user and group are ignored when systemd is used. # If you need to run mysqld under a different user or group, # customize your systemd unit file for mariadb according to the # instructions in http://fedoraproject.org/wiki/Systemd [client] port=3306 socket=/opt/soft/mysql/data/mysql.sock [mysqld_safe] # # include all files from the config directory # !includedir /etc/my.cnf.d -
第七步:进入bin文件夹:
cd /opt/soft/mysql/bin,初始化数据库:
./mysqld --defaults-file=/etc/my.cnf --basedir=/opt/soft/mysql/ --datadir=/opt/soft/mysql/data/ --user=mysql –initialize -
第八步:记录初始化生成的密码
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-baiFXPmG-1686644594197)(C:\Users\zhangwei\AppData\Roaming\Typora\typora-user-images\image-20230613162000099.png)]](https://img-blog.csdnimg.cn/a30220c595874710b586e639b57fa381.png)
-
第九步:将mysql放在本地系统服务中:
cp /opt/soft/mysql/support-files/mysql.server /etc/init.d/mysql -
第十步:添加到系统服务器:
chkconfig --add mysql,查看是否添加成功:chkconfig --list mysql![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-SmUB7TxQ-1686644594198)(C:\Users\zhangwei\AppData\Roaming\Typora\typora-user-images\image-20230613162038624.png)]](https://img-blog.csdnimg.cn/24c9143f65ba47a398e474943ce27be7.png)
-
第十一步:启动mysql:
service mysql start,如果失败,切换mysql用户:su mysql![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-tcTwXPY0-1686644594198)(C:\Users\zhangwei\AppData\Roaming\Typora\typora-user-images\image-20230613162108967.png)]](https://img-blog.csdnimg.cn/3a8af6856f9c4b0bb83fbe504e3f0638.png)
-
第十二步:进入bin目录:
cd /opt/soft/mysql/bin,登录mysql:进入mysql的bin目录下,登录mysql:./mysql -u root –p,密码为第九步记录的初始密码![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-3MiPkhDG-1686644594198)(C:\Users\zhangwei\AppData\Roaming\Typora\typora-user-images\image-20230613162132188.png)]](https://img-blog.csdnimg.cn/4acbb3be2c4f41c19a110c3ffb76cb1f.png)
-
第十三步:更改密码:
ALTER USER 'root'@'localhost' IDENTIFIED BY '123456'; -
第十四步:刷新权限:
flush privileges; -
第十五步:开放远程连接:
use mysql select host,user from user; update user set host='%' where user='root'; flush privileges;![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-QYwBrCtL-1686644594199)(C:\Users\zhangwei\AppData\Roaming\Typora\typora-user-images\image-20230613162226331.png)]](https://img-blog.csdnimg.cn/4fcdc546e47d429f87d62a464b0dba7a.png)
-
第十六步:使用navicat远程连接测试


















