专栏首页Cyylog技术MySQL部署之源码安装

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>

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

我来说两句

0 条评论
登录 后参与评论

相关文章

  • Docker_001

    Cyylog
  • Go_学习之Docke容器

    Cyylog
  • Zabbix源码安装

    注意连接数据库那个步骤需要将服务器ip改为127.0.0.1 不能使用localhost

    Cyylog
  • 12.2 MySQL安装

    MySQL安装目录概要 cd /usr/local/src wget http://mirrors.sohu.com/mysql/MySQL-5.6/mysql...

    运维小白
  • mysql 3.x拿webshell

    mysql> Create TABLE demo (sanr text NOT NULL);

    py3study
  • macOS 安装 mysql

    打开下载页面 https://dev.mysql.com/downloads/mysql/5.7.html ,下载镜像安装文件。

    我是一条小青蛇
  • MySQL-5.7.10主主同步的安装和配置

    这里安装的是最新的MySQL 5.7.10(5.7.12、5.7.13(后续更新版本可能类似)有些区别,安装过程中遇到错误可搜索下本文,也许可以找到解决办法...

    一见
  • 安装mysql

    超级大猪
  • docker安装mysql及navicat远程连接

    华创信息技术
  • 服务器的Mysql初始化设置

    继上篇博客记录了服务器的初始化安全设置之后,本篇文章会记录Mysql数据库的初始化安全设置。在操作mysql之前,最好先行备份,毕竟有“备”无患嘛。

    Originalee

扫码关注云+社区

领取腾讯云代金券