记录一下自己安装centos7安装mysql
1.检查系统是否有mysql,如果有统统删除
find / -name mysql
删除命令
rm -rf /etc/selinux/targeted/active/modules/100/mysql
rm -rf /usr/share/mysql
rm -rf /usr/lib64/mysql
2.创建临时目录,下载并上传mysql-5.7.30-el7-x86_64.tar.gz
mkdir -p /Lehand/tmp /Lehand/tools /Lehand/web /Lehand/service /Lehand/api /Lehand/third /Lehand/upload /Lehand/data /Lehand/jdk /Lehand/bak
3.解压,把解压后的文件夹移动到/Lehand/tools
tar -zxvf mysql-5.7.30-el7-x86_64.tar.gz
mv mysql-5.7.30-el7-x86_64 ../tools
cd ../tools
mv mysql-5.7.30-el7-x86_64 mysql
4.添加用户
groupadd mysql
useradd -r -g mysql mysql
id mysql
5.创建data目录
cd /Lehand/data
mkdir mysql
设置权限
chown 777 mysql
6.更改mysql目录权限
chown -R mysql:mysql /Lehand/tools/mysql
7.配置my.cnf文件
rm -f /etc/my.cnf
vim /etc/my.cnf
[client]
port = 33006
default-character-set=utf8
socket = /Lehand/tools/mysql/mysql.sock
[mysqld]
# 一般配置选项
basedir = /Lehand/tools/mysql
datadir = /Lehand/data/mysql
socket=/Lehand/tools/mysql/mysql.sock
max_connections=200
port = 33006
character-set-server=utf8
default_storage_engine = InnoDB
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
8.初始化mysql
cd /Lehand/tools/mysql/bin
./mysqld --initialize-insecure --user=mysql --basedir=/Lehand/tools/mysql --datadir=/Lehand/data/mysql
正确的结果
2022-03-10T08:04:59.243908Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2022-03-10T08:05:01.186604Z 0 [Warning] InnoDB: New log files created, LSN=45790
2022-03-10T08:05:01.788668Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2022-03-10T08:05:02.091122Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: c988acec-a048-11ec-b4ec-525400622edd.
2022-03-10T08:05:02.161651Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2022-03-10T08:05:04.068487Z 0 [Warning] CA certificate ca.pem is self signed.
2022-03-10T08:05:04.644909Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
初始化错误:
把data/mysql的文件清楚干净,再次初始化即可(保证文件夹都存在);
cd /Lehand/data/mysql/
rm -rf *
cd ../
chown 777 mysql
9.启动mysql
./mysqld_safe --user=mysql &
service mysql status
报错: .pid 就需要看日志;
在日志文件 /var/log/mysql/error.log 中可以看到具体的ERROR
信息:Could not create unix socket lock file /var/run/mysql/mysql.sock.lock。
这种错误一般都是目录不存在或者权限不足,所以我们直接使用命令 mkdir -p /var/run/mysql/ 创建该目录即可,然后可以设置目录权限 chown -R mysql:mysql /var/run/mysql/ 。
10.修改密码,设置外网可以访问
./mysql -u root -p
use mysql;
update user set authentication_string=password('root') where user='root';
update user set host='%' where user ='root';
flush privileges;
select host,user from user;
exit;
firewall-cmd --zone=public --add-port=3306/tcp --permanent
firewall-cmd --reload
firewall-cmd --list-ports
11.设置开机启动
cp /Lehand/tools/mysql/support-files/mysql.server /etc/init.d/mysql
chkconfig --list
chkconfig mysql on
mysql的状态
service mysql status
关闭 mysql
service mysql stop
启动 mysql
service mysql start
12.添加mysql环境变量
vim /etc/profile
export PATH=$PATH:/Lehand/tools/mysql/bin
更新资源文件
source /etc/profile
mysql -u root -p
重新初始化;
各种报错解决方案:
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 单元测试从入门到精通
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律