mysql源码安装详解

举报
rivers 发表于 2021/12/22 22:35:07 2021/12/22
【摘要】 文章目录 MYSQL简介实验环境安装步骤总结mysql常用配置文件参数常见mysql 启动报错总结 MYSQL简介 查看mysql简介 查看cmake编译mysql 实验环境 数...

MYSQL简介

查看mysql简介

查看cmake编译mysql

实验环境

数据库 IP 系统版本 mysql版本
MYSQL 192.168.10.11 CentOS 7.4 5.7.20

安装步骤

  • 下载安装包

    [root@localhost ~]# wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz
    --2021-04-18 20:58:11--  https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz
    Resolving downloads.mysql.com (downloads.mysql.com)... 137.254.60.14
    Connecting to downloads.mysql.com (downloads.mysql.com)|137.254.60.14|:443... connected.
    HTTP request sent, awaiting response... 302 Found
    Location: https://cdn.mysql.com/archives/mysql-5.7/mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz [following]
    --2021-04-18 20:58:12--  https://cdn.mysql.com/archives/mysql-5.7/mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz
    Resolving cdn.mysql.com (cdn.mysql.com)... 184.86.92.235
    Connecting to cdn.mysql.com (cdn.mysql.com)|184.86.92.235|:443... connected.
    HTTP request sent, awaiting response... 200 OK
    Length: 641127384 (611M) [application/x-tar-gz]
    Saving to: ‘mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz’
    
    100%[===================================================================>] 641,127,384 10.5MB/s   in 61s    
    
    2021-04-18 20:59:13 (10.1 MB/s) - ‘mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz’ saved [641127384/641127384]
    
    [root@localhost ~]# ls
    anaconda-ks.cfg  back_yum  he.txt  mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz
    
    
        
       
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
  • 解压 安装包

    [root@localhost ~]# mv mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz /usr/local/
    [root@localhost local]# tar xf mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz 
    [root@localhost local]# ln -s mysql-5.7.20-linux-glibc2.12-x86_64/  mysql
    [root@localhost local]# ll mysql
    
    
        
       
    • 1
    • 2
    • 3
    • 4
    • 5
  • 创建用户

    [root@localhost local]# useradd -M -s /sbin/nologin mysql
    
        
       
    • 1
  • 修改目录/usr/local/mysql的属主属组

    [root@localhost local]# chown -R mysql:mysql mysql
    [root@localhost local]# ll mysql
    lrwxrwxrwx 1 mysql mysql 36 Apr 18 21:22 mysql -> mysql-5.7.20-linux-glibc2.12-x86_64/
    [root@localhost local]# 
    
        
       
    • 1
    • 2
    • 3
    • 4
  • 设置环境变量

    [root@localhost bin]# echo 'export PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
    
    [root@localhost bin]# source /etc/profile.d/mysql.sh
    
    [root@localhost bin]# echo $PATH
    /usr/local/mysql/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
    
        
       
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
  • 建立数据存放目录,并修改权限

    [root@localhost bin]# mkdir -p /data/mysql
    [root@localhost bin]# chown -R mysql.mysql /data/mysql/
    [root@localhost bin]# 
    
        
       
    • 1
    • 2
    • 3
  • 初始化数据库

    [root@localhost bin]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --datadir=/data/mysql/ 
    2021-04-18T13:31:12.749412Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
    2021-04-18T13:31:13.310688Z 0 [Warning] InnoDB: New log files created, LSN=45790
    2021-04-18T13:31:13.376643Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
    2021-04-18T13:31:13.437436Z 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: 584ca535-a04a-11eb-bee7-000c29e5f134.
    2021-04-18T13:31:13.438276Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
    2021-04-18T13:31:13.439087Z 1 [Note] A temporary password is generated for root@localhost: !4wowa:8MipQ
    [root@localhost bin]# 
    请注意,这个命令的最后会生成一个临时密码,此处密码是!4wowa:8MipQ。每个人初始化密码不一样,后面初次登陆用
    
        
       
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
  • 创建mysql配置文件

    [root@localhost bin]# cat > /etc/my.cnf <<EOF
    > [mysqld]
    > basedir=/usr/local/mysql
    > datadir=/data/mysql/
    > socket=/tmp/mysql.sock
    > port=3306
    > pid-file=/data/mysql/mysql.pid
    > user=mysql
    > skip-name-resolve
    > EOF
    
    [root@localhost bin]# cat /etc/my.cnf
    [mysqld]
    basedir=/usr/local/mysql
    datadir=/data/mysql/
    socket=/tmp/mysql.sock
    port=3306
    pid-file=/data/mysql/mysql.pid
    user=mysql
    skip-name-resolve
    [root@localhost bin]# 
    
    
        
       
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
  • 设置服务启动脚本

    [root@localhost bin]# cd ../support-files/
    [root@localhost support-files]# \cp -af mysql.server /etc/init.d/mysqld
    root@localhost support-files]# sed -ri 's#^(basedir=).*#\1/usr/local/mysql#g' /etc/init.d/mysqld
    [root@localhost support-files]# sed -ri 's#^(datadir=).*#\1/data/mysql/#g' /etc/init.d/mysqld
    
        
       
    • 1
    • 2
    • 3
    • 4
  • 启动mysql

    [root@localhost support-files]# 
    [root@localhost support-files]# /etc/init.d/mysqld start
    Starting MySQL. SUCCESS! 
    
        
       
    • 1
    • 2
    • 3
  • 测试:

    [root@localhost ~]# ss -lant|grep 3306
    LISTEN     0      80          :::3306                    :::*                  
    [root@localhost ~]# mysql -uroot -p
    Enter password: 
    
    mysql> quit
    Bye
    [root@localhost ~]# 
    
        
       
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8

总结

mysql常用配置文件参数

参数 说明
port = 3306 设置监听端口
socket = /tmp/mysql.sock 指定套接字文件位置
basedir = /usr/local/mysql 指定MySQL的安装路径
datadir = /data/mysql 指定MySQL的数据存放路径
pid-file = /data/mysql/mysql.pid 指定进程ID文件存放路径
user = mysql 指定MySQL以什么用户的身份提供服务
skip-name-resolve 禁止MySQL对外部连接进行DNS解析 使用这一选项可以消除MySQL进行DNS解析的时间。 若开启该选项,则所有远程主机连接授权都要使用IP地址方 式否则MySQL将无法正常处理连接请求

常见mysql 启动报错总结

  • 报错1

    [root@localhost support-files]# /etc/init.d/mysqld start
    Starting MySQL... ERROR! The server quit without updating PID file (/data/mysql/mysql.pid).
    [root@localhost support-files]# 
    关于网上对这个错误的总结,很多人都说权限问题,其实不管我们怎么给权限,好像都报错,很多时候都是因为配置文件有问题,才导致的,如果出现此错误,建议检查配置文件
    
        
       
    • 1
    • 2
    • 3
    • 4
  • 报错2

    Systemctl restart mariadb.service
    Job for mariadb.service failed because the control process exited with error code. See "systemctl status mariadb.service" and "journalctl -xe" for details.
    解决方法:查看错误日志:journalctl –xe
    
    查看端口是否被占用:netstat -tnlp|grep 3306
    
    最终的判断,MYSQL进程已经存在,无法启动Mariadb,解决方法,停止原来的MYSQL服务;
    
        
       
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
  • 报错3

    Redirecting to /bin/systemctl restart  mariadb.service
    Job for mariadb.service failed because the control process exited with error code. See "systemctl status mariadb.service" and "journalctl -xe" for details.
    ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)解决方法:
    
    使用journalctl –xe查看MYSQL错误信息;
    关闭服务器selinux安全策略,关闭防火墙setenforce 0
    检查MYSQL|Mariadb通过什么样的方式部署的;
    检查其配置文件/etc/my.cnf,datadir数据目录是否配置;检查socket是否配置正确
    确认数据库的数据目录mysql用户是否拥有读写权限;
    检查数据库目录是否初始化,是否包括mysql、test基础库;
    检查socket文件所在的路径,是否存在socket文件,权限是否正确;
    
        
       
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11

文章来源: rivers.blog.csdn.net,作者:宝山的博客,版权归原作者所有,如需转载,请联系作者。

原文链接:rivers.blog.csdn.net/article/details/115840939

【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。