欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

在mac上使用tar.gz安装mysql

程序员文章站 2022-03-22 13:14:04
官方: download: https://dev.mysql.com/downloads/mysql/ mysql参考文档:https://dev.mysql.com/doc/ 环境: macOS Mojave 10.14.2 用户: 管理员用户,期间没有新建mysql用户或组 安装包: mysq ......

官方:

  • download: https://dev.mysql.com/downloads/mysql/
  • mysql参考文档:https://dev.mysql.com/doc/

环境:

  • macos mojave 10.14.2

用户:

  • 管理员用户,期间没有新建mysql用户或组

安装包:

  • mysql-8.0.13-macos10.14-x86_64.tar.gz

安装配置

1.解压
下载的tar.gz解压后,并移动到/usr/local/mysql,目录结构如下:

$ pwd
/usr/local
$ tree mysql -l 1
mysql
├── license
├── license.router
├── readme
├── readme.router
├── bin
├── data
├── docs
├── include
├── lib
├── man
├── run
├── share
└── support-files

实际上是按照unix目录结构的规范,建议这么做。
本人实际操作过程中,只是通过sudo ln -s ${mysql_home} /usr/local/mysql,创建了一个软链接。
解压命令:tar -xzvf ${filename}

2.修改权限:sudo chown -r usr:group /usr/local/mysql

3.初始化

$ cd /usr/local/mysql
$ bin/mysqld --initialize --user=ephemerid --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
2019-01-20t05:50:19.601053z 0 [system] [my-013169] [server] /workspaces/programfiles/mysql-8.0.13-macos10.14-x86_64/bin/mysqld (mysqld 8.0.13) initializing of server in progress as process 1045
2019-01-20t05:50:19.603274z 0 [warning] [my-010159] [server] setting lower_case_table_names=2 because file system for /usr/local/mysql/data/ is case insensitive
2019-01-20t05:50:21.143953z 5 [note] [my-010454] [server] a temporary password is generated for root@localhost: a_mbvrbnd0*r
2019-01-20t05:50:22.000946z 0 [system] [my-013170] [server] /workspaces/programfiles/mysql-8.0.13-macos10.14-x86_64/bin/mysqld (mysqld 8.0.13) initializing of server has completed

ephemerid是我的用户名,改成自己的。
后面两个选项的含义,见后文my-011011
前面提到过,本人使用了软链接,所以控制台信息中看到的mysql实际的目录。
注意这个“a temporary password is generated for root@localhost”

5.启动

$ support-files/mysql.server start
starting mysql
. success! 

6.连接及修改初始密码

$ bin/mysql -uroot -pa_mbvrbnd0*r
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 8
server version: 8.0.13

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> show databases;
error 1820 (hy000): you must reset your password using alter user statement before executing this statement.

mysql> alter user 'root'@'localhost' identified by 'pass123456';
query ok, 0 rows affected (0.02 sec)

mysql> show databases;
+--------------------+
| database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.01 sec)

mysql> exit
bye

!!!平常输入密码的时候不要直接添加在-p选项后面了,会被看到的,一定要注意安全!!!

第一次登陆时,会提示需要重置密码:

alter user 'root'@'localhost' identified by 'pass123456';

7.停止服务

$ support-files/mysql.server stop
shutting down mysql
.. success! 

eorror

the server quit without updating pid file

在未初始化,就启动时出现了:

$ sudo ./support-files/mysql.server start
password:
starting mysql
. error! the server quit without updating pid file (/usr/local/mysql/data/ephemerid.local.pid).

解决

初始化一下,即上文提到的mysqld --initialize

my-011011

在初始化时,没有找到有效的mysql目录以及mysql data目录。

$ sudo ./bin/mysqld --initaialize --user=ephemerid
2019-01-20t05:13:45.476844z 0 [system] [my-010116] [server] /workspaces/programfiles/mysql-8.0.13-macos10.14-x86_64/bin/mysqld (mysqld 8.0.13) starting as process 993
2019-01-20t05:13:45.480320z 0 [warning] [my-010159] [server] setting lower_case_table_names=2 because file system for /workspaces/programfiles/mysql-8.0.13-macos10.14-x86_64/data/ is case insensitive
2019-01-20t05:13:45.487935z 1 [error] [my-011011] [server] failed to find valid data directory.
2019-01-20t05:13:45.488090z 0 [error] [my-010020] [server] data dictionary initialization failed.
2019-01-20t05:13:45.488119z 0 [error] [my-010119] [server] aborting
2019-01-20t05:13:45.488808z 0 [system] [my-010910] [server] /workspaces/programfiles/mysql-8.0.13-macos10.14-x86_64/bin/mysqld: shutdown complete (mysqld 8.0.13)  mysql community server - gpl.

解决

就是添加的两个选项,即上文提到的--basedir--datadir
了解更多,参考:

  • https://dev.mysql.com/doc/refman/8.0/en/data-directory-initialization-mysqld.html

以上。