这篇别看了,当年写的时候是个菜逼,当然现在也是
二进制安装
mysql_install_db --defaults-file=/data/mysqldata/3306/my.cnf --datadir=/data/mysqldata/3306/data --basedir=/usr/local/mysql --user=mysql
2015-12-04 21:18:14 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize
2015-12-04 21:18:14 [ERROR] Child process: /usr/local/mysql/bin/mysqldterminated prematurely with errno= 32
2015-12-04 21:18:14 [ERROR] Failed to execute /usr/local/mysql/bin/mysqld --defaults-file=/data/mysqldata/3306/my.cnf --bootstrap --datadir=/data/mysqldata/3306/data --lc-messages-dir=/usr/local/mysql/share --lc-messages=en_US --basedir=/usr/local/mysql
-- server log begin --
/usr/local/mysql/bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
mysql_install_db 被废弃了,取而代之的是 mysqld –initialize
报错还提示找不到libaio.so.1
error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
Warning
MySQL has a dependency on the libaio library. Data directory initialization and subsequent server startup steps will fail if this library is not installed locally. If necessary, install it using the appropriate package manager. For example, on
Yum-based systems:
shell> yum search libaio # search for info
shell> yum install libaio # install library
Or, on APT-based systems:
shell> apt-cache search libaio # search for info
shell> apt-get install libaio1 # install library
Mysql 对 libaio library有依赖关系。
安装好libaio后
root@Fan:/data# /usr/local/mysql/bin/mysqld --initialize --defaults-file=/data/mysqldata/3306/my.cnf --datadir=/data/mysqldata/3306/data --basedir=/usr/local/mysql --user=mysql
2015-12-04T13:22:01.848446Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2015-12-04T13:22:03.639997Z 0 [Warning] InnoDB: New log files created, LSN=45790
2015-12-04T13:22:04.002719Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2015-12-04T13:22:04.167369Z 0 [ERROR] unknown variable 'defaults-file=/data/mysqldata/3306/my.cnf'
2015-12-04T13:22:04.167408Z 0 [ERROR] Aborting
unknown variable ‘defaults-file=/data/mysqldata/3306/my.cnf’
–defaults-file选项应在最前
Then invoke mysqld as follows (enter the command on a single line with the–defaults-file option first):
shell> bin/mysqld --defaults-file=/opt/mysql/mysql/etc/my.cnf
--initialize --user=mysql
initialize the data directory, invoke mysqld with the–initialize or –initialize-insecure option, depending on whether you want the server to generate a random initial password for the ‘root’@’localhost’ account.
On Unix and Unix-like systems, it is important to make sure that the database directories and files are owned by themysql login account so that the server has read and write access to them when you run it later. To ensure this if you run mysqld as root, include the–user option as shown here:
重要的是要确保数据库的目录和文件都属于MySQL登录账号,使服务器对他们拥有读写权限。如果你通过root用户运行mysqld, 带上–user参数
shell> bin/mysqld --initialize --user=mysql
shell> bin/mysqld --initialize-insecure --user=mysql
Regardless of platform, use–initialize for “secure by default” installation (that is, including generation of a random initialrootpassword). In this case, the password is marked as expired and you will need to choose a new one. With the–initialize-insecure option, noroot password is generated; it is assumed that you will assign a password to the account in timely fashion before putting the server into production use.
–initialize 与 –initialize-insecure不同的是,他会创建一个随机的root密码
继续执行,又报错。
root@Fan:/data/mysqldata/3306# /usr/local/mysql/bin/mysqld --defaults-file=/data/mysqldata/3306/my.cnf --initialize-insecure --user=mysql
2015-12-04T13:27:38.504948Z 0 [Warning] 'NO_ZERO_DATE', 'NO_ZERO_IN_DATE' and 'ERROR_FOR_DIVISION_BY_ZERO' sql modes should be used with strict mode. They will be merged with strict mode in a future release.
2015-12-04T13:27:38.504999Z 0 [Warning] 'NO_AUTO_CREATE_USER' sql mode was not set.
2015-12-04T13:27:38.508994Z 0 [ERROR] You have enabled the binary log, but you haven't provided the mandatory server-id. Please refer to the proper server start-up parameters documentation
2015-12-04T13:27:38.509070Z 0 [ERROR] Aborting
root@Fan:/data/mysqldata/3306# /usr/local/mysql/bin/mysqld --defaults-file=/data/mysqldata/3306/my.cnf --initialize-insecure --user=mysql
重要的是You have enabled the binary log, but you haven’t provided the mandatory server-id. Please refer to the proper server start-up parameters documentation
启用了binlog,但是没有设置server-id,于是我在my.cnf中添加server-id
再次初始化成功了,但是没有任何提示,很奇怪
尝试启动mysql,成功
mysql@Fan:~$ mysqld_safe --defaults-file=/data/mysqldata/3306/my.cnf &
[1] 28843
mysql@Fan:~$ 151204 21:32:05 mysqld_safe Logging to '/data/mysqldata/3306/data/../mysql-error.log'.
151204 21:32:05 mysqld_safe Starting mysqld daemon with databases from /data/mysqldata/3306/data
mysql@Fan:/data/mysqldata/3306$ mysql -uroot -p -S /data/mysqldata/3306/mysql.sock
Enter password: ---我并未输入密码,而是直接回车,因为之前用的参数是--initialize-insecure
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.9-log MySQL Community Server (GPL)
Copyright (c) 2000, 2015, 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>
mysql>
mysql> select user,host from mysql.user;
+-----------+-----------+
| user | host |
+-----------+-----------+
| mysql.sys | localhost |
| root | localhost |
+-----------+-----------+
2 rows in set (0.00 sec)
改密码
mysql@Fan:/data/mysqldata/3306$ mysqladmin -S /data/mysqldata/3306/mysql.sock -uroot -p password mysql
Enter password:
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.