Linux环境:Centos7.9
Linux上使用二进制方式安装mysql
上传并解压mysql包
tar xf mysql-5.7.36-linux-glibc2.12-x86_64.tar.gz -C /usr/local
创建软链接
cd /usr/local
ln -sv mysql-5.7.36-linux-glibc2.12-x86_64 mysql
为mysql下的所有文件和目录创建mysql的所属者和所属组
chown -R mysql.mysql mysql/*
1、初始化mysql
/usr/local/mysql/bin/mysql_install_db --user=mysql --datadir=/usr/local/mysql/data
报错:(不同版本可能会存在不同的问题)
解决方法:(提供一个解决思路)
根据报错信息提示,将命令纠正为
/usr/local/mysql/bin/mysqld --initialize --user=mysql --datadir=/usr/local/mysql/data
出现新错误:
根据报错提示,删除该文件夹下的所有文件
[root@www local]# rm -rf ./mysql/data/*
继续执行该初始化命令
成功执行,生成一个mysql密码
2、修改mysql主配置文件
[root@localhost ~]# vim /etc/my.cnf
[mysqld]
datadir=/usr/local/mysql/data
socket=/tmp/mysql.sock
[mysqld_safe]
log-error=mysql.log
pid-file=mysql.pid
3、为mysql提供sysv服务脚本
[root@localhost ~]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
4、启动mysql
将mysql添加为系统服务
chkconfig --add mysqld
设置为开机自启动
chkconfig mysqld on
启动mysql
systemctl start mysqld
查看mysql状态
systemctl status mysqld
5、修改mysql的root密码
配置环境变量:
[root@www ~]# vim /etc/profile.d/mysql.sh
export PATH=/usr/local/mysql/bin:$PATH
[root@www ~]# source /etc/profile.d/mysql.sh
修改密码:
W,%X!6:1hyh/是之前自动生成的原始密码,123456是设置的新密码
[root@www ~]# mysqladmin -uroot -p'W,%X!6:1hyh/' password '123456'
使用新密码登录mysql:
[root@www ~]# mysql -uroot -p123456
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.36 MySQL Community Server (GPL)
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
mysql环境准备完成!!!