一、下载mysql
//官网 https://dev.mysql.com/downloads/mysql/
二、安装
2.1 将mysql包上传至linux并解压
tar -zxvf mysql-8.0.25-el7-x86.tar.gz
2.2 将解压的文件复制到/usr/local/mysql目录
cp mysql-8.0.25-el7-x86.tar.gz /usr/local/mysql
2.3 修改/etc/my.conf文件
[client] port=3306 socket=/data/mysql/mysql.sock [mysqld] port=3306 user=root socket=/data/mysql/mysql.sock basedir=/usr/local/mysql/mysql-8.0.25-el7-x86_64 datadir=/usr/local/mysql/mysql-8.0.25-el7-x86_64/data log-error=/data/mysql/error.log pid-file = /data/mysql/mysql.pid transaction_isolation = READ-COMMITTED character-set-server = utf8mb4 collation-server = utf8mb4_general_ci lower_case_table_names = 1 default_authentication_plugin=mysql_native_password # Disabling symbolic-links is recommended to prevent assorted security risks # 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 #[mysqld_safe] #log-error=/var/log/mariadb/mariadb.log #pid-file=/var/run/mariadb/mariadb.pid # # include all files from the config directory # !includedir /etc/my.cnf.d
2.4 初始化mysql
cd /software/mysql/bin ./mysqld --user=mysql --basedir=/software/mysql --datadir=/data/mysql --initialize
2.5 启动mysql
/software/mysql/support-files/mysql.server start
2.6 登录mysql
/software/mysql/bin/mysql -u root –p
初始密码可查看:/data/mysql/error.log文件
2.7 修改密码
>mysql set password=password('root'); >mysql grant all privileges on *.* to root@'%' identified by 'root'; >mysql flush privileges;