1. 解压 tar -zxvf mysql-5.7.34-linux-glibc2.12-x86_64.tar.gz
mv mysql-5.7.34-linux-glibc2.12-x86_64 mysql
2. 先检查是否有mysql用户组和mysql用户,没有就添加有就忽略: groups mysql
添加用户组和用户 groupadd mysql && useradd -r -g mysql mysql
3. 创建数据目录并赋予权限
mkdir -p /data/mysql
chown mysql:mysql -R /data/mysql
4. 修改配置文件 vim /etc/my.cnf
[mysqld] bind-address=0.0.0.0 port=3306 user=mysql basedir=/usr/local/mysql 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 explicit_defaults_for_timestamp=true
5. 初始化
cd /usr/local/mysql/bin/
./mysqld --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql/ --datadir=/data/mysql/ --user=mysql --initialize
6. 查看密码
cat /data/mysql/mysql.err
7. 启动mysql
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
cd /usr/local/mysql/bin/ && service mysql start
修改密码
1. 登录
./mysql -u root -p
2. 修改密码
SET PASSWORD = PASSWORD('123456');
ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER;
FLUSH PRIVILEGES;
3. 刷新规则允许外部访问
use mysql #访问mysql库
update user set host = '%' where user = 'root'; #使root能再任何host访问
FLUSH PRIVILEGES; #刷新
1,将服务文件复制一份到init.d下,并重命名为mysqld
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
2,对文件赋予执行权限
chmod +x /etc/init.d/mysqld 或 chmod 777 /etc/init.d/mysqld
3,增加mysqld服务
chkconfig --add mysqld
4,查询mysqld服务情况
chkconfig --list mysqld
卸载
1. kill -9 pid
2. rm -rf /root/.mysql_sercret
3. rm -rf /var/lib/mysql
4. rm -rf /usr/local/mysql
5. rm -rf /data/mysql