1、官网下载mysql安装包:mysql-8.0.27-linux-glibc2.12-x86_64.tar.xz
2、解压安装包:tar xvf mysql-8.0.27-linux-glibc2.12-x86_64.tar.xz
3、重命名:mv mysql-8.0.27-linux-glibc2.12-x86_64 mysql-8.0.27
4、复制到/usr/local:sudo mv mysql-8.0.20 /usr/local/
5、创建用户组:sudo groupadd mysql
6、添加用户:useradd -r -g mysql mysql
7、创建MySQL数据目录:
sudo mkdir -p /data
cd data
sudo mkdir -p mysql
8、修改拥有者:udo chown mysql:mysql -R /data/mysql
9、生成编辑配置文件:sudo vim /etc/my.cnf
[mysqld]
bind-address=0.0.0.0
port=3306
user=mysql
basedir=/usr/local/mysql-8.0.27
datadir=/data/mysql
socket=/tmp/mysql.sock
log-error=/data/mysql/mysql.err
pid-file=/data/mysql/mysql.pid
#character config
character_set_server=utf8mb4
symbolic-links=0
10、初始化mysql
cd /usr/local/mysql-8.0.27/
sudo ./mysqld --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql-8.0.27/ --datadir=/data/mysql/ --user=mysql --initialize
11、查看初始密码
sudo cat /data/mysql/mysql.err
12、启动mysql
12.1 service mysql start 出现问题
Failed to start mysqld.service: Unit mysqld.service not found.
12.2 ps -ef|grep mysql 检查,确实没有相关进程启来
12.3 sudo find / -name mysql.server 查找
12.4 复制mysq.server
> sudo cp /usr/local/mysql-8.0.27/support-files/mysql.server /etc/init.d
12.5 sudo /etc/init.d/mysql status
如果启动仍然出错:Failed to start mysql.service: Unit mysql.service is masked,可能是之前使用apt-get 安装过mysql,服务被标记过,解除后即可启动:systemctl unmask mysql.service
12.6 启动:service mysql start
12.7 查看状态:sudo service mysql status
13、连接mysql时报错
将libtinfo.so.5文件放到/lib文件夹下,文件下载链接,提取码: o9gw
----------------------------------------------------------arm架构安装mysql并修改密码--------------------------------------------------------------------------
1、安装mysql: yum install -y mysql-community-server-8
2、安装过程中需要用到的包,直接yum install
如果出现mariadb冲突的问题,直接yum remove -y mariadb,然后重新执行
3、启动服务并查看进程
systemctl start mysqld
systemctl enable mysqld
4、查看初始密码:
grep -i password /var/log/mysqld.log
mysql_secure_installation
5、登录mysql
mysql -uroot -p
6、开启mysql服务:
systemctl start mysqld
在这里mysql服务可以正常启动了,以下是修改mysql8及以上版本的密码策略
1、查看密码策略等级:
SHOW VARIABLES LIKE ‘validate_password%’;
2、修改root密码:
ALTER USER ‘root’@’%’ IDENTIFIED WITH mysql_native_password BY ‘0403’;
3、密码策略一时改不过来的话,将所有值都写在/etc/my.cnf的[mysqld]节中
[mysqld]
validate_password.check_user_name=OFF
validate_password.length=4
validate_password.mixed_case_count=0
validate_password.number_count=0
validate_password.policy=0
validate_password.special_char_count=0
4、重启mysqld,结果密码策略就会改变