Mysql 编译安装

本贴最后更新于 2192 天前,其中的信息可能已经东海扬尘

一、环境准备

1.软件下载

<font size=4>【Mysql 5.6 下载】

2.依赖安装

``` [root@iZ2zeibok6t3svl00dy8jyZ ~]# yum install -y ncurses-devel gcc-c++ cmake ```

3.创建用户

``` [root@iZ2zeibok6t3svl00dy8jyZ ~]# useradd mysql -s /sbin/nologin ```

4.创建目录

``` [root@iZ2zeibok6t3svl00dy8jyZ ~]# mkdir -p /data/mysql/soft # mysql软件安装目录 [root@iZ2zeibok6t3svl00dy8jyZ ~]# mkdir -p /data/mysql/data/{data,bin_log,relay_log} # mysql数据目录 ```

二、编译安装

1.编译参数

|Cmake 编译参数||||
|---|
|

参数名|描述|默认值|备注|
|-DCMAKE_INSTALL_PREFIX| 软件安装目录 |/usr/local/mysql | |
|-DMYSQL_DATADIR| 数据目录 | | |
|-DSYSCONFDIR| 配置文件目录 |/etc/my.cnf| |
|-DMYSQL_UNIX_ADDR|Socket 目录及文件 |/tmp/mysql.sock| |
|-DDEFAULT_CHARSET| 服务器字符集 |latin1| |
|-DDEFAULT_COLLATION| 服务器排序 |latin1_swedish_ci| |
|-DENABLED_LOCAL_INFILE| 加载文件 |OFF| |
|-DWITHOUT_EXAMPLE_STORAGE_ENGINE| 存储引擎 | OFF| |
|-DWITHOUT_FEDERATED_STORAGE_ENGINE| 存储引擎 | OFF| |
|-DWITHOUT_PARTITION_STORAGE_ENGINE| 存储引擎 | OFF| |

强制安装的引擎:InnoDB(默认), MyISAM, MERGE, MEMORY, CSV

### 2.编译安装 ``` [root@iZ2zeibok6t3svl00dy8jyZ data]# tar -xvzf mysql-5.6.41.tar.gz [root@iZ2zeibok6t3svl00dy8jyZ mysql-5.6.41]# cmake -DCMAKE_INSTALL_PREFIX=/data/mysql/soft \ -DMYSQL_DATADIR=/data/mysql/data/data \ -DSYSCONFDIR=/data/mysql/soft/my.cnf \ -DMYSQL_UNIX_ADDR=/data/mysql/data/data/mysql.sock \ -DDEFAULT_CHARSET=utf8mb4 \ -DDEFAULT_COLLATION=utf8mb4_general_ci \ -DENABLED_LOCAL_INFILE=1

[root@iZ2zeibok6t3svl00dy8jyZ mysql-5.6.41]# make -j # -j:使用全部 CPU 来编译,提升速度
[root@iZ2zeibok6t3svl00dy8jyZ mysql-5.6.41]# make install

</font>
### 3.数据库初始化
<font size=4>

[root@iZ2zeibok6t3svl00dy8jyZ ~]# cd /usr/local/mysql/
[root@iZ2zeibok6t3svl00dy8jyZ mysql]# scripts/mysql_install_db --user=mysql --basedir=/data/mysql/soft --datadir=/data/mysql/data/data

</font>


### 4.参数配置
<font size=4>

[root@iZ2zeibok6t3svl00dy8jyZ ~]# vim /data/mysql/soft/my.cnf
[mysqld]
port = 13306
server_id = 11
basedir = /data/mysql/soft
datadir = /data/mysql/data/data
binlog_format=mixed
log_bin=/data/mysql/data/bin_log/bin_log
relay-log=/data/mysql/data/relay_log/relay_log
explicit_defaults_for_timestamp=true
skip-name-resolve
back_log = 600
max_connections = 1000
max_connect_errors = 6000
open_files_limit = 65535
table_open_cache = 512
max_allowed_packet = 4M
binlog_cache_size = 1M
max_heap_table_size = 8M
tmp_table_size = 16M
sort_buffer_size = 8M
innodb_buffer_pool_size = 2048M
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 2M
slow_query_log = on
long_query_time = 1
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

</font>
### 5.环境变量
<font size=4>

[root@iZ2zeibok6t3svl00dy8jyZ ~]# echo 'export PATH=/data/mysql/soft/bin:/data/mysql/soft/lib:$PATH' >>/etc/profile
[root@iZ2zeibok6t3svl00dy8jyZ ~]# source /etc/profile

</font>

### 6.目录权限
<font size=4>

[root@iZ2zeibok6t3svl00dy8jyZ ~]# chown -R root.mysql /data/mysql/soft
[root@iZ2zeibok6t3svl00dy8jyZ ~]# chown -R mysql.mysql /data/mysql/data

</font>

### 7.开机启动
<font size=4>

[root@iZ2zeibok6t3svl00dy8jyZ ~]# cp /data/mysql/soft/support-files/mysql.server /etc/init.d/mysqld
[root@iZ2zeibok6t3svl00dy8jyZ ~]# chmod 755 /etc/init.d/mysqld
[root@iZ2zeibok6t3svl00dy8jyZ ~]# chkconfig mysqld on

</font>

## 三、数据库安全
### 1.启动服务
<font size=4>

[root@iZ2zeibok6t3svl00dy8jyZ ~]# service mysqld restart
Shutting down MySQL.. SUCCESS!
Starting MySQL. SUCCESS!
[root@iZ2zeibok6t3svl00dy8jyZ ~]#

</font>
### 2.安全设置
<font size=4>

[root@iZ2zeibok6t3svl00dy8jyZ ~]#/data/mysql/soft/bin/mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!

In order to log into MySQL to secure it, we'll need the current
password for the root user. If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none): # 输入当前 root 密码,如果没有直接回车
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.

Set root password? [Y/n] Y # 是否设置 root 密码
New password: # 输入 root 密码
Re-enter new password: # 再次确定 root 密码
Password updated successfully!
Reloading privilege tables..
... Success!

By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] Y # 清除匿名用户
... Success!

Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] n # 是否禁止 root 远程登录
... skipping.

By default, MySQL comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] Y # 是否清除 test 数据库

  • Dropping test database...
    ... Success!
  • Removing privileges on test database...
    ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] Y # 是否重新加载权限
... Success!

All done! If you've completed all of the above steps, your MySQL
installation should now be secure.

Thanks for using MySQL!

Cleaning up...

</font>
  • MySQL

    MySQL 是一个关系型数据库管理系统,由瑞典 MySQL AB 公司开发,目前属于 Oracle 公司。MySQL 是最流行的关系型数据库管理系统之一。

    690 引用 • 535 回帖
  • 数据库

    据说 99% 的性能瓶颈都在数据库。

    340 引用 • 708 回帖

相关帖子

欢迎来到这里!

我们正在构建一个小众社区,大家在这里相互信任,以平等 • 自由 • 奔放的价值观进行分享交流。最终,希望大家能够找到与自己志同道合的伙伴,共同成长。

注册 关于
请输入回帖内容 ...