MySQL部署之源码安装
时间:2022-07-23
本文章向大家介绍MySQL部署之源码安装,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。
所需要的依赖及安装MySQL的包
# yum -y update
# yum -y groupinstall "Development Tools"
# yum -y install gcc gcc-c++ ncurses ncurses-devel bison libgcrypt perl make cmake
# wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-boost-5.7.24.tar.gz
在系统中添加运行mysqld进程的用户mysql
[root@mysql_source ~]# groupadd mysql
[root@mysql_source ~]# useradd -M -g mysql -s /sbin/nologin mysql
在系统中添加自定义MySQL数据库目录及其他必要目录
[root@mysql_source ~]# mkdir -p /usr/local/mysqld/{data,mysql,log,tmp}
[root@mysql_source ~]# chown -R mysql:mysql /usr/local/mysqld/*
将mysql-boost-5.7.24.tar.gz解压到当前目录,并执行部署操作
[root@mysql_source ~]# tar xf mysql-boost-5.7.24.tar.gz
[root@mysql_source ~]# cd mysql-5.7.24
[root@mysql_source mysql-5.7.24]#
$ cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysqld/mysql
-DMYSQL_DATADIR=/usr/local/mysqld/data
-DWITH_BOOST=/root/mysql-5.7.24/boost
-DDEFAULT_CHARSET=utf8
......
-- Configuring done
-- Generating done
-- Build files have been written to: /root/mysql-5.7.24
[root@mysql_source mysql-5.7.24]# echo $?
0
[root@mysql_source mysql-5.7.24]# make -j `lscpu | awk 'NR==4{ print $2 }'`
......
[100%] Built target udf_example
[root@mysql_source mysql-5.7.24]# echo $?
0
[root@mysql_source mysql-5.7.24]# make install
......
-- Installing: /usr/local/mysqld/mysql/support-files/mysql.server
[root@mysql_source mysql-5.7.24]# echo $?
0
[root@mysql_source mysql-5.7.24]#
Congratulations Complete!
初始化MySQL安装配置
1.提升MySQL命令为系统级别命令
[root@mysql_source ~]# echo "export PATH=$PATH:/usr/local/mysqld/mysql/bin" >>/etc/profile
[root@mysql_source ~]# source /etc/profile
2.拷贝默认配置文件至/etc/my.cnf中
[root@mysql_source mysql]# chown -R mysql.mysql /usr/local/mysqld/*
[root@mysql_source ~]# cd /usr/local/mysqld/mysql/mysql-test/include
[root@mysql_source include]# cp /etc/{my.cnf,my.cnf.bak}
[root@mysql_source include]# cp default_mysqld.cnf /etc/my.cnf
cp:是否覆盖"/etc/my.cnf"? y
[root@mysql_source include]# vim /etc/my.cnf
[mysqld]
basedir = /usr/local/mysqld/mysql
datadir = /usr/local/mysqld/data
tmpdir = /usr/local/mysqld/tmp
socket = /usr/local/mysqld/tmp/mysql.sock
pid_file = /usr/local/mysqld/tmp/mysqld.pid
log_error = /usr/local/mysqld/log/mysql_error.log
slow_query_log_file = /usr/local/mysqld/log/slow_warn.log
server_id = 11
user = mysql
port = 3306
bind-address = 0.0.0.0
character-set-server = utf8
default_storage_engine = InnoDB
3.执行数据库服务初始化操作
[root@mysql_source mysql]# mysqld --defaults-file=/etc/my.cnf --initialize --user='mysql'
[root@mysql_source mysql]#
4.启动mysqld服务
[root@mysql_source mysql]# mysqld_safe --defaults-file=/etc/my.cnf &
[1] 25705
2018-12-28T09:19:35.334751Z mysqld_safe Logging to '/usr/local/mysqld/log/mysql_error.log'.
2018-12-28T09:19:35.379829Z mysqld_safe Starting mysqld daemon with databases from /usr/local/mysqld/data
5.设置mysql.socket软链接到mysql命令指定的目录中
[root@mysql_source ~]# ln -s /usr/local/mysqld/tmp/mysql.sock /tmp/mysql.sock
6.配置mysqld服务的管理工具
[root@mysql_source support-files]# cd /usr/local/mysqld/mysql/support-files
[root@mysql_source support-files]# cp mysql.server /etc/init.d/mysqld
[root@mysql_source support-files]# chkconfig --add mysqld
[root@mysql_source support-files]# chkconfig mysqld on
登录数据库并进行更改密码
[root@mysql_source mysql]# grep "password" /usr/local/mysqld/log/mysql_error.log
2018-12-28T09:18:34.214401Z 1 [Note] A temporary password is generated for root@localhost: ejhszb2:m3wJ
[root@mysql_source tmp]# mysql -uroot -p"ejhszb2:m3wJ"
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 2
Server version: 5.7.24-log
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
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> alter user 'root'@'localhost' identified by "(Cyylog..1228)";
平常中常用的MySQL部署参数:<参考使用>
-DCMAKE_INSTALL_PREFIX=/usr/local/mysqld/mysql
-DMYSQL_DATADIR=/usr/local/mysqld/data
-DDOWNLOAD_BOOST=1
-DWITH_BOOST=/root/mysql-5.7.24/boost
-DSYSCONFDIR=/etc
-DWITH_INNOBASE_STORAGE_ENGINE=1
-DWITH_PARTITION_STORAGE_ENGINE=1
-DWITH_FEDERATED_STORAGE_ENGINE=1
-DWITH_BLACKHOLE_STORAGE_ENGINE=1
-DWITH_MYISAM_STORAGE_ENGINE=1
-DENABLED_LOCAL_INFILE=1
-DENABLE_DTRACE=0
-DDEFAULT_CHARSET=utf8
-DDEFAULT_COLLATION=utf8_general_ci
-DWITH_EMBEDDED_SERVER=1
绕过验证密码登录 修改密码
[root@mysql ~]# vim /etc/my.cnf
[mysqld]
skip-grant-tables=1
[root@mysql ~]# systemctl restart mysqld
[root@mysql ~]# mysql -uroot
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 2
Server version: 5.7.24 MySQL Community Server (GPL)
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
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> alter user 'root'@'localhost' identified by "(Cyylog..1229)";
ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> show tables;
......
......
......
| user |
+---------------------------+
31 rows in set (0.00 sec)
mysql> select User,Host,authentication_string from user;
+---------------+-----------+-------------------------------------------+
| User | Host | authentication_string |
+---------------+-----------+-------------------------------------------+
| root | localhost | *C4571A0C807D96143700250EC4BA41780025A97F |
| mysql.session | localhost | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
| mysql.sys | localhost | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
+---------------+-----------+-------------------------------------------+
3 rows in set (0.00 sec)
mysql> update user set authentication_string=password('(Cyylog@@1229)') where user='root';
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 1
[root@mysql ~]# vim /etc/my.cnf
[mysqld]
#skip-grant-tables=1
[root@mysql ~]# systemctl restart mysqld
[root@mysql ~]# mysql -uroot -p"(Cyylog@@1229)"
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 2
Server version: 5.7.24 MySQL Community Server (GPL)
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
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>
- linq to sql的多条件动态查询(上)
- 极简区块链手册:什么是区块链?什么是比特币?
- Nginx+keepalived实现高可用
- 来一波Linux中查看cpu、磁盘、内存、网络的命令
- PXE+kickstart网络安装CentOS7.4系统及过程中各种报错
- [MSDN]通过避免下列 10 个常见 ASP.NET 缺陷使网站平稳运行
- Flask-配置与调试
- PXE+kickstart网络安装CentOS7.4系统及过程中各种报错
- MSDN官方的ASP.Net异步页面的经典示例代码
- Nginx反向代理、负载均衡功能
- 2018即将面临的12个云安全风险
- Flask快速入门,知识整理
- python的reduce()函数
- 企业级memcached缓存数据库结合php使用与web管理memcached
- MySQL 教程
- MySQL 安装
- MySQL 管理与配置
- MySQL PHP 语法
- MySQL 连接
- MySQL 创建数据库
- MySQL 删除数据库
- MySQL 选择数据库
- MySQL 数据类型
- MySQL 创建数据表
- MySQL 删除数据表
- MySQL 插入数据
- MySQL 查询数据
- MySQL where 子句
- MySQL UPDATE 查询
- MySQL DELETE 语句
- MySQL LIKE 子句
- mysql order by
- Mysql Join的使用
- MySQL NULL 值处理
- MySQL 正则表达式
- MySQL 事务
- MySQL ALTER命令
- MySQL 索引
- MySQL 临时表
- MySQL 复制表
- 查看MySQL 元数据
- MySQL 序列 AUTO_INCREMENT
- MySQL 处理重复数据
- MySQL 及 SQL 注入
- MySQL 导出数据
- MySQL 导入数据
- MYSQL 函数大全
- MySQL Group By 实例讲解
- MySQL Max()函数实例讲解
- mysql count函数实例
- MYSQL UNION和UNION ALL实例
- MySQL IN 用法
- MySQL between and 实例讲解
- [-Flutter 自组篇-] 蛛网图+绘制+动画实践
- Kotlin类型系统竟如此简单
- 以人为本 | Android 11 的消息通知
- RxJava取消订阅的各种方式的实现
- [- Flutter 基础篇 -] ListView的使用
- Emoji表情在Android JNI中的兼容性问题详解
- 一个吸顶Item的简单实现方法分享
- [- Flutter福利篇 -] Hero转场组件共享 — 附赠-路由动画工具类
- Hue执行多条语句问题
- Android仿抖音列表效果
- com.android.support版本冲突解决方法
- [-Flutter趣玩篇-] 出神入化的Align+动画
- Hive Impala和Hue集成LDAP
- Android仿QQ分组实现二级菜单展示
- Android RecyclerView实现拼团倒计时列表实例代码