centos7 安装Mysql8并配置可以远程访问
1.卸载centos7自带的MariaDB
# rpm -qa|grep mariadb
# yum erase mariadb
2. 下载mysql压缩包
# wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.33-el7-x86_64.tar.gz
# useradd mysql -M -s /sbin/nologin // 添加mysql账户
# tar xvf mysql-8.tar.xz
# mv mysql-8 mysql
# mv mysql /usr/local
# cd /usr/local/mysql
# mkdir data // 创建data目录,用来存储数据库内容
3.
# chow -R mysql:mysql /usr/local/mysql // 对目录进行授权
# cd bin
# ./mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data // 初始化系统会分配一个临时密码,需要保存好,后续用来登录,然后更改密码
# vim ~/.bash_profile // 加入环境变量
PATH=$PATH:$HOME/xxxxxxxx:/usr/local/mysql/bin
# source ~/.bash_profile
4. 将启动脚本mysql.server放入/etc/init.d目录中,让服务器每次重启后都能自动启动数据库
# cd /usr/local/mysql
# cp -a support-files/mysql.server /etc/init.d
# chmod a+x /etc/init.d/mysql.server
# ln -s /usr/lib64/libtinfo.so.6.1 /usr/lib64/libtinfo.so.5
5. 启动mysql, 并更改密码
# /etc/init.d/mysql.server start
# mysql -h 127.0.0.1 -u root -p // 登录mysql,输入初始分配的密码
> Enter password: 输入行原始分配密码
> alter user 'root'@'localhost' identified by '123456'; // 更改为新密码
6. 切换到mysql库中,修改user表单密码值
> use mysql;
> show tables;
> alter user 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';
设置可以通过外部远程访问:
# firewall-cmd --zone=public --query-port=3306/tcp; # 开启3306端口
https://www.cnblogs.com/haoxuanchen2014/p/17344278.html