1、下载并解压 mysql安装包
https://downloads.mysql.com/archives/community/
放到服务器后解压
-C 放到指定文件夹
tar -xvf mysql-8.0.30-linux-glibc2.12-x86_64.tar.xz -C /usr/local
修改mysql 文件夹名
mv mysql-8.0.30-linux-glibc2.12-x86_64 mysql
2、创建mysql 用户和用户组
>groupadd mysql >useradd -r -g mysql mysql
3、创建数据文件夹data,并给权限
> mkdir -p /usr/local/data # 给mysql用户权限 > chown -R mysql:mysql /usr/local/data > chmod -R 755 /usr/local/data
4、给mysql的log目录权限
chown -R mysql:mysql /var/log
5、修改mysql配置文件
> vim /etc/my.cnf
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
[mysqld] #datadir=/var/lib/mysql #socket=/var/lib/mysql/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 bind-address=0.0.0.0 port=3306 user=mysql basedir=/usr/local/mysql datadir=/usr/local/data socket=/tmp/mysql.sock #socket=/data/mysql/mysql.sock log-error=/var/log/mysql.err pid-file=/var/log/mysql.pid ##character config character_set_server=utf8mb4 symbolic-links=0 explicit_defaults_for_timestamp=true lower_case_table_names=1View Code
6、初始化mysql
> ./mysqld --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql/ --datadir=/usr/local/data/ --user=mysql --initialize
查看mysql临时密码
> cat /var/log/mysql.err
7、启动mysql 修改初始密码
>cd /usr/local/mysql/support-files
>./mysql.server start
查看mysql进程
>ps -ef|grep mysql
登录mysql
>cd /usr/local/mysql/bin
修改密码
> ./mysql -u root -p
>ALTER USER 'root'@'localhost' IDENTIFIED BY '123456'; >FLUSH PRIVILEGES;
8、开放远程连接
>use mysql; >update user set user.Host='%' where user.User='root'; >flush privileges;
标签:log,mysql8,安装,data,CentOS7,usr,mysql,local,user From: https://www.cnblogs.com/ychun/p/16880380.html