MYSQL简介
查看mysql简介
查看cmake编译mysql
实验环境
安装步骤
- 下载安装包
[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
- 解压 安装包
[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
- 创建用户
[root@localhost local]# useradd -M -s /sbin/nologin mysql
- 修改目录/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]#
- 设置环境变量
[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
- 建立数据存放目录,并修改权限
[root@localhost bin]# mkdir -p /data/mysql [root@localhost bin]# chown -R mysql.mysql /data/mysql/ [root@localhost bin]#
- 初始化数据库
[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。每个人初始化密码不一样,后面初次登陆用
- 创建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]#
- 设置服务启动脚本
[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
- 启动mysql
[root@localhost support-files]# [root@localhost support-files]# /etc/init.d/mysqld start Starting MySQL. SUCCESS!
- 测试:
[root@localhost ~]# ss -lant|grep 3306 LISTEN 0 80 :::3306 :::* [root@localhost ~]# mysql -uroot -p Enter password: mysql> quit Bye [root@localhost ~]#
总结
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]# 关于网上对这个错误的总结,很多人都说权限问题,其实不管我们怎么给权限,好像都报错,很多时候都是因为配置文件有问题,才导致的,如果出现此错误,建议检查配置文件
- 报错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服务;
- 报错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文件,权限是否正确;