Mac下,源码安装Mysql 5.7.23

  • 1. 下载

Select Version:
 [5.7.23]
Select Operating System:
 [Source Code]
Select OS Version:
 [Generic Linux(Architecture Independent)]

Compressed TAR Archive    5.7.23    49.5M
(mysql-5.7.23.tar.gz)    MD5: 3398bb99df0ca926f161d56e9cefa73d | Signature

[Compressed TAR Archive, Includes Boost Headers    5.7.23    46.8M    ]
(mysql-boost-5.7.23.tar.gz)    MD5: de108e7ff350aa10402a3e707a4b4c75 | Signature

要选择[Compressed TAR Archive, Includes Boost Headers    5.7.23    46.8M    ]版本,带boostheader的

  • 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=/usr/local/mysql/db_data -DDOWNLOAD_BOOST=1 \
-DWITH_BOOST=/Users/aa/Downloads/mysql-5.7.23/boost

ps:在ubuntu18下,会报错:Curses library not found.  Please install appropriate package

需要apt-get install libncurses5-dev

  • 3. 配置数据目录权限

chown -R _mysql:_mysql /usr/local/mysql/db_data

  • 4. 编译并安装

make
make install

  • 5. 初始化

bin/mysqld --initialize --user=mysql --datadir=/usr/local/mysql/db_data --basedir=/usr/local/mysql/

如果报如下错:
./mysqld --initialize --user=mysql --datadir=/usr/local/mysql/db_data --basedir=/usr/local/mysql/
2018-08-15T09:42:55.440966Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-08-15T09:42:55.443137Z 0 [ERROR] --initialize specified but the data directory has files in it. Aborting.
2018-08-15T09:42:55.443175Z 0 [ERROR] Aborting
解决:删除db_data目录,然后重新执行

成功log如下:

2018-08-15T09:44:08.453003Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-08-15T09:44:08.456327Z 0 [Warning] Setting lower_case_table_names=2 because file system for /usr/local/mysql/db_data/ is case insensitive
2018-08-15T09:44:08.456876Z 0 [Warning] One can only use the --user switch if running as root

2018-08-15T09:44:08.664378Z 0 [Warning] InnoDB: New log files created, LSN=45790
2018-08-15T09:44:08.715545Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2018-08-15T09:44:08.782728Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: c1c99242-a06f-11e8-9598-627c46ebc829.
2018-08-15T09:44:08.793014Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2018-08-15T09:44:08.794615Z 1 [Note] A temporary password is generated for root@localhost: qty4;7Apt5sx

  • 6. 启动mysql,报错如下

./mysql.server start
Password:
Starting MySQL
.Logging to '/usr/local/mysql/db_data/localhost.err'.
 ERROR! The server quit without updating PID file (/usr/local/mysql/db_data/localhost.pid).

 解决:将/usr/local/mysql/db_data,数据目录设置777

  • 7. 登录mysql

 mysql -uroot -pqty4;7Apt5sx
 use mysql, show databases 等语句都报错如下:
 ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

 做如下3部操作即可
 step 1: SET PASSWORD = PASSWORD('新密码');

 step 2: ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER;

 step 3: flush privileges;

  • 8. 增加demo用户

insert into mysql.user(Host,User,authentication_string, ssl_cipher, x509_issuer, x509_subject)
values
("%","demo",password("demo"), '', '', '');

  • 9. 为用户授权

grant all privileges on *.* to demo@"%" identified by 'demo';
flush privileges;
 

猜你喜欢

转载自blog.csdn.net/cin_ie/article/details/81708907