离线安装Linux-Generic版本MySql

发布时间:2026/5/15 14:01:56

离线安装Linux-Generic版本MySql 包准备选择Linux-Generic下载带有glibc的包mysql地址https://downloads.mysql.com/archives/community/解压tar -zxvf [压缩文件路径] -C /usr/local #把解压的包修改为mysql mv /usr/local/mysql-x-x-x /usr/local/mysql #在mysql包下创建data文件夹 mkdir data创建用户组#查看有没有该用户没有再执行以下命令创建 groups mysql cd /usr/local #创建用户组 groupadd mysql #创建用户 useradd -r -g mysql mysql授权以下目录如果没有自行创建#授权 chown -R mysql:mysql /usr/local/mysql chown -R mysql:mysql /usr/local/mysql/data chown -R mysql:mysql /var/lib/mysql初始化cd /usr/local/mysql #初始化初始化成功之后有个密码需要记住 bin/mysqld --initialize --usermysql --basedir/usr/local/mysql --datadir/usr/local/mysql/data #执行之后会在data目录下创建了很多文件出现以下类似消息记住临时密码密码在最后rootlocalhost: [密码]23-06-14T02:23:57.909676Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2023-06-14T02:23:57.915911Z 0 [Warning] One can only use the --user switch if running as root 2023-06-14T02:23:58.169643Z 0 [Warning] InnoDB: New log files created, LSN45790 2023-06-14T02:23:58.237810Z 0 [Warning] InnoDB: Creating foreign key constraint system tables. 2023-06-14T02:23:58.300597Z 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: 8498cfcc-0a5a-11ee-bffe-000c29e11db3. 2023-06-14T02:23:58.302385Z 0 [Warning] Gtid table is not ready to be used. Table mysql.gtid_executed cannot be opened. 2023-06-14T02:23:58.304827Z 1 [Note] A temporary password is generated for rootlocalhost: Hea/GEk7tufJ如果初始化出现关于libaio1错误的需要安装libaio1#地址https://debian.pkgs.org/11/debian-main-amd64/libaio1_0.3.112-9_amd64.deb.html #安装 sudo dpkg -i libaio1_0.3.112-9_amd64.deb启动mysqlcd /usr/local/mysql support-files/mysql.server start出现以下类似消息查看XXX.err日志看一下有没有报错的没有就算成功了Starting MySQL .Logging to /usr/local/mysql/data/WC.err. *登录mysql#输入以下命令键入之前/bin/mysqld执行消息给的临时密码 /bin/mysql -u root -p #修改登录密码 alter user rootlocalhost identified by 123456;开启远程连接可选如果你想让其他电脑也能连上该数据库use mysql select host, user, authentication_string, plugin from user; grant all on *.* to root%; flush privileges; #如果出现错误执行以下 update user set host % where user root; flush privileges; grant all on *.* to root%; flush privileges;配置最好在最后再配置这个因为有些问题是在配这个才会发生网上一些教程真是坑人在系统中新建/etc/my.cnf文件内容如下[client] # 客户端设置即客户端默认的连接参数 port 3306 # 端口号 user mysql # linux的用户 [mysqld] # 服务端基本设置 # 基础设置 basedir /usr/local/mysql # MySQL安装根目录 datadir /usr/local/mysql/data # MySQL数据文件所在位置 #socket /tmp/mysql.sock # 用于本地连接的socket套接字mysqld守护进程生成了这个文件该文件在启动过一次mysql之后才会有具体位置自己找一下我的建议不要配空着默认即可 log-error /usr/local/mysql/data/error.log # 数据库错误日志文件 #pid-file /usr/local/mysql/data/mysql.pid # pid文件所在目录该文件在启动过一次mysql之后才会有具体位置自己找一下一般名称为[计算机名.pid]我的建议是不要配空着默认即可 max_connections 400 # 最大连接数 character-set-server utf8mb4 # 设置client连接mysql时的字符集,防止乱码 explicit_defaults_for_timestamp true # TIMESTAMP如果没有显示声明NOT NULL允许NULL值 lower_case_table_names 1 # 是否对sql语句大小写敏感1表示不敏感 max_allowed_packet 128M # SQL数据包发送的大小如果有BLOB对象建议修改成1G配置服务闲之前那个启动方式麻烦才配置不闲麻烦这个可以不配置cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql #start启动 stop停止 restart重启 status查看状态。例 systemctl start mysql配置环境同上sudo vim /etc/profi #或者gedit #编写以下内容或者直接在终端敲命令也行 export MYSQL_HOME/usr/local/mysql export PATH$PATH:$MYSQL_HOME/bin #刷新配置 source /etc/profi #这样你就可以直接敲mysql不用到/usr/local/mysql/bin/mysql敲了

相关新闻