Mac编译安装Mysql5.7.17

1、下载并解压安装包:

国内镜像地址:http://mirrors.sohu.com/mysql/MySQL-5.7/mysql-boost-5.7.17.tar.gz
解压:tar -zxvf mysql-boost-5.7.17.tar.gz

2、执行cmake

cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DENABLED_LOCAL_INFILE=1 -DMYSQL_USER=_mysql -DMYSQL_TCP_PORT=3306 -DMYSQL_DATADIR=/data/mysql -DDOWNLOAD_BOOST=1 -DWITH_BOOST=/Users/tianjiawei/software/mysql-5.7.17/boost

3、配置目录权限

chown -R _mysql:_mysql /data/mysql

4、编译并安装

make && make install

5、安装数据库并启动

cd /usr/local/mysql/bin
./mysqld --initialize --user=mysql --datadir=/data/mysql --explicit_defaults_for_timestamp=true
cd /usr/local/mysql/support-files
./mysql.server start

6、修改数据库root用户密码(首次进入密码为空)

修改:/usr/local/mysql/support-files/mysql.server第278行(mysql_safe启动的那行代码 加上如下参数,忽略身份验证)

 $bindir/mysqld_safe --datadir="$datadir" --pid-file="$mysqld_pid_file_path" $other_args

改成

$bindir/mysqld_safe --user=mysql --skip-grant-tables --skip-networking --datadir="$datadir" --pid-file="$mysqld_pid_file_path" $other_args

然后执行

cd /usr/local/mysql/support-files
./mysql.server restart
cd /usr/local/mysql/bin
mysql -u root
mysql>use mysql;
mysql>UPDATE user SET authentication_string=PASSWORD('mysql54321') where USER='root';
mysql>FLUSH PRIVILEGES;
mysql>quit;

还原/usr/local/mysql/support-files/mysql.server文件
重新启动mysqld
修改密码方法如下:

mysql -uroot -p
Enter password: <输入新设的密码mysql54321>
mysql>SET PASSWORD = PASSWORD('mysql54321');
mysql>ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER;
mysql>flush privileges;
mysql>quit;

你可能感兴趣的:(Mac编译安装Mysql5.7.17)