linux(mac) 编译安装MySQL

时间:2022-10-22 00:18:59

Reference: https://blog.csdn.net/Tzhennan/article/details/80565235

 

官方下载地址:  https://dev.mysql.com/downloads/mysql/
从mysql5.5起,mysql源码安装开始使用cmake
#mac 安装cmake
$ brew install cmake
#centos 安装cmake
$ yum install -y cmake


#相关编译选项
安装时路径相关的配置
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql # 安装路径
-DMYSQL_DATADIR=/usr/local/mysql/data # MySQL的数据目录
-DSYSCONFDIR=/etc # MySQL配置文件路径


存储引擎相关的配置
#若要明确指定编译某引擎,可使用类似如下的选项:
-DWITH_INNOBASE_STORAGE_ENGINE=1
-DWITH_ARCHIVE_STORAGE_ENGINE=1
-DWITH_BLACKHOLE_STORAGE_ENGINE=1
-DWITH_FEDEFATED_STORAGE_ENGINE=1


#若要明确指定不编译某引擎,可使用类似如下的选项:
-DWITHOUT_<engine-name>_ENGINE=1
#如
-DWITHOUT_EXAMPLE_STORAGE_ENGINE=1
-DWITHOUT_FEDERATED_STORAGE_ENGINE=1
-DWITHOUT_PARTITION_STORAGE_ENGINE=1


其他配置项
-DMYSQL_TCP_PORT=3306
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock
-DENABLED_LOCAL_INFILE=1
-DEXTRA_CHARSETS=all
-DDEFAULT_CHARSET=utf8
-DDEFAULT_COLLATION=utf8_general_ci
-DWITH_DEBUG=0
-DENABLED_PROFILING=1


-DWITH_READLINE=1
-DWITH_SSL=system
-DWITH_ZLIB=system
-DWITH_LIBWRAP=0


#编译安装
#解压缩
$ tar -zxvf mysql-boost-5.7.22.tar.gz
$ cd mysql-5.7.22
#编译安装
$ cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
        -DMYSQL_DATADIR=/usr/local/mysql/data \
        -DWITH_INNOBASE_STORAGE_ENGINE=1 \
        -DWITH_ARCHIVE_STORAGE_ENGINE=1 \
        -DWITH_ARCHIVE_STORAGE_ENGINE=1 \
        -DWITH_READLINE=1 \
        -DWITH_LIBWRAP=0 \
        -DMYSQL_UNIX_ADDR=/tmp/mysql.sock \
        -DDEFAULT_CHARSET=utf8 \
        -DENABLE_DOWNLOADS=1 \
        -DDEFAULT_COLLATION=utf8_general_ci \
        -DMYSQL_USER=_mysql \
        -DWITH_BOOST=/Users/tzhennan/Downloads/software/mysql-5.7.22/boost \
        -DDOWNLOAD_BOOST=1
$ make
$ make install

#修改属组和属主
$ chown -R _mysql:_mysql /usr/local/mysql/

 

2.修改MySQL的登录设置: 
# vim /etc/my.cnf 
在[mysqld]的段中加上一句:skip-grant-tables 
例如: 
[mysqld] 
datadir=/var/lib/mysql 
socket=/var/lib/mysql/mysql.sock 
skip-grant-tables 

log-bin=/opt/mysql540/log/mysql-bin
log_bin= /opt/mysql540/log/mysql-bin

basedir=/opt/mysql540

datadir=/opt/mysql540/data
socket=/opt/mysql540/mysql.sock
pid-file=/opt/mysql540/mysql.pid
log-error=/opt/mysql540/error.log

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

server_id=1
binlog_format='ROW'

保存并且退出vi。

 

3.重新启动mysqld 
support-files/mysql.server restart 
Stopping MySQL: [ OK ] 
Starting MySQL: [ OK ]

4.登录并修改MySQL的root密码 
# mysql 
Welcome to the MySQL monitor. Commands end with ; or \g. 
Your MySQL connection id is 3 to server version: 3.23.56 
Type 'help;' or '\h' for help. Type '\c' to clear the buffer. 
mysql> USE mysql ; 
Database changed 
mysql> UPDATE user SET Password = password ( 'new-password' ) WHERE User = 'root' ; 
Query OK, 0 rows affected (0.00 sec) 
Rows matched: 2 Changed: 0 Warnings: 0 
mysql> flush privileges ; 
Query OK, 0 rows affected (0.01 sec) 
mysql> quit

5.将MySQL的登录设置修改回来 
# vim /etc/my.cnf 
将刚才在[mysqld]的段中加上的skip-grant-tables删除 
保存并且退出vim

6.重新启动mysqld 
# service mysqld restart 
Stopping MySQL: [ OK ] 
Starting MySQL: [ OK ]

 

改为bind-address = 0.0.0.0即可

 

1、新建用户远程连接mysql数据库
grant all on *.* to admin@'%' identified by '123456' with grant option; 
flush privileges;
允许任何ip地址(%表示允许任何ip地址)的电脑用admin帐户和密码(123456)来访问这个mysql server。
注意admin账户不一定要存在。

2、支持root用户允许远程连接mysql数据库
grant all privileges on *.* to 'root'@'%' identified by '123456' with grant option;
flush privileges;