本篇是记录安装 MySQL 过程中遇到的问题以及解决方法的,顺利安装步骤可参考我的另一篇文章。
CentOS 7 安装 MySQL 5.6.4 – 通过二进制包方式安装
1.下载编译好的 tar 包
打开 MySQL 官网的下载页面,拉至最底部。
如要选择指定版本的 MySQL,点击右侧的 “Looking for the latest GA version?”
select operation system --》 选择 Linux Getneric
select OS version --》 选择 32位 或 64位
2. 解压安装包
[root@localhost software]$ tar -zvxf mysql-5.6.42-linux-glibc2.12-x86_64.tar.gz
[root@localhost vicky]# ll
总用量 321272
drwxr-xr-x. 13 root root 191 11月 7 12:06 mysql-5.6.42-linux-glibc2.12-x86_64
-rwxrw-rw-. 1 vicky vicky 328979165 11月 6 10:10 mysql-5.6.42-linux-glibc2.12-x86_64.tar.gz
drwxr-xr-x. 2 vicky vicky 6 11月 7 11:22 公共
drwxr-xr-x. 2 vicky vicky 6 11月 7 11:22 模板
drwxr-xr-x. 2 vicky vicky 6 11月 7 11:22 视频
drwxr-xr-x. 2 vicky vicky 6 11月 7 11:22 图片
drwxr-xr-x. 2 vicky vicky 6 11月 7 11:22 文档
drwxr-xr-x. 2 vicky vicky 6 11月 7 11:22 下载
drwxr-xr-x. 2 vicky vicky 6 11月 7 11:22 音乐
drwxr-xr-x. 2 vicky vicky 6 11月 7 11:22 桌面
3.将解压后的文件夹中的内容拷贝到目录 /usr/local/mysql 下
[root@localhost vicky]# cp mysql-5.6.42-linux-glibc2.12-x86_64 /usr/local/mysql -r
[root@localhost vicky]# cd /usr/local/mysql
[root@localhost mysql]# ll
总用量 48
drwxr-xr-x. 2 root root 4096 11月 7 12:08 bin
-rw-r--r--. 1 root root 17987 11月 7 12:07 COPYING
drwxr-xr-x. 3 root root 18 11月 7 12:07 data
drwxr-xr-x. 2 root root 55 11月 7 12:07 docs
drwxr-xr-x. 3 root root 4096 11月 7 12:07 include
drwxr-xr-x. 3 root root 4096 11月 7 12:08 lib
drwxr-xr-x. 4 root root 30 11月 7 12:07 man
drwxr-xr-x. 10 root root 4096 11月 7 12:07 mysql-test
-rw-r--r--. 1 root root 2496 11月 7 12:08 README
drwxr-xr-x. 2 root root 30 11月 7 12:07 scripts
drwxr-xr-x. 28 root root 4096 11月 7 12:08 share
drwxr-xr-x. 4 root root 4096 11月 7 12:08 sql-bench
drwxr-xr-x. 2 root root 136 11月 7 12:07 support-files
4.查看 mysql 组和 mysql 用户是否存在
[root@localhost mysql]# cat /etc/passwd |grep mysql
[root@localhost mysql]# cat /etc/group |grep mysql
[root@localhost mysql]#
添加 mysql 组和 mysql 用户
[root@localhost mysql]# cat /etc/group |grep mysql
mysql:x:1001:
[root@localhost mysql]# useradd -r -g mysql mysql
[root@localhost mysql]# cat /etc/passwd |grep mysql
mysql:x:988:1001::/home/mysql:/bin/bash
5.修改 /usr/local/mysql/ 目录的组和用户
进入安装mysql软件目录:执行命令 cd /usr/local/mysql
修改当前目录拥有者为mysql用户:执行命令 chown -R mysql:mysql ./
[root@localhost mysql]# chown -R mysql:mysql ./
[root@localhost mysql]# ll
总用量 48
drwxr-xr-x. 2 mysql mysql 4096 11月 7 12:08 bin
-rw-r--r--. 1 mysql mysql 17987 11月 7 12:07 COPYING
drwxr-xr-x. 3 mysql mysql 18 11月 7 12:07 data
drwxr-xr-x. 2 mysql mysql 55 11月 7 12:07 docs
drwxr-xr-x. 3 mysql mysql 4096 11月 7 12:07 include
drwxr-xr-x. 3 mysql mysql 4096 11月 7 12:08 lib
drwxr-xr-x. 4 mysql mysql 30 11月 7 12:07 man
drwxr-xr-x. 10 mysql mysql 4096 11月 7 12:07 mysql-test
-rw-r--r--. 1 mysql mysql 2496 11月 7 12:08 README
drwxr-xr-x. 2 mysql mysql 30 11月 7 12:07 scripts
drwxr-xr-x. 28 mysql mysql 4096 11月 7 12:08 share
drwxr-xr-x. 4 mysql mysql 4096 11月 7 12:08 sql-bench
drwxr-xr-x. 2 mysql mysql 136 11月 7 12:07 support-files
6 .安装数据库:
在 /usr/local/mysql 下执行命令 ./scripts/mysql_install_db --user=mysql
[root@localhost mysql]# ./scripts/mysql_install_db --user=mysql
Installing MySQL system tables...2018-11-07 12:53:08 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-11-07 12:53:08 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
2018-11-07 12:53:08 0 [Note] ./bin/mysqld (mysqld 5.6.42) starting as process 57014 ...
2018-11-07 12:53:08 57014 [Note] InnoDB: Using atomics to ref count buffer pool pages
2018-11-07 12:53:08 57014 [Note] InnoDB: The InnoDB memory heap is disabled
2018-11-07 12:53:08 57014 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2018-11-07 12:53:08 57014 [Note] InnoDB: Memory barrier is not used
2018-11-07 12:53:08 57014 [Note] InnoDB: Compressed tables use zlib 1.2.11
2018-11-07 12:53:08 57014 [Note] InnoDB: Using Linux native AIO
2018-11-07 12:53:08 57014 [Note] InnoDB: Using CPU crc32 instructions
2018-11-07 12:53:08 57014 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2018-11-07 12:53:08 57014 [Note] InnoDB: Completed initialization of buffer pool
2018-11-07 12:53:08 57014 [Note] InnoDB: The first specified data file ./ibdata1 did not exist: a new database to be created!
2018-11-07 12:53:08 57014 [Note] InnoDB: Setting file ./ibdata1 size to 12 MB
2018-11-07 12:53:08 57014 [Note] InnoDB: Database physically writes the file full: wait...
2018-11-07 12:53:08 57014 [Note] InnoDB: Setting log file ./ib_logfile101 size to 48 MB
2018-11-07 12:53:08 57014 [Note] InnoDB: Setting log file ./ib_logfile1 size to 48 MB
2018-11-07 12:53:08 57014 [Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0
2018-11-07 12:53:08 57014 [Warning] InnoDB: New log files created, LSN=45781
2018-11-07 12:53:08 57014 [Note] InnoDB: Doublewrite buffer not found: creating new
2018-11-07 12:53:08 57014 [Note] InnoDB: Doublewrite buffer created
2018-11-07 12:53:08 57014 [Note] InnoDB: 128 rollback segment(s) are active.
2018-11-07 12:53:08 57014 [Warning] InnoDB: Creating foreign key constraint system tables.
2018-11-07 12:53:08 57014 [Note] InnoDB: Foreign key constraint system tables created
2018-11-07 12:53:08 57014 [Note] InnoDB: Creating tablespace and datafile system tables.
2018-11-07 12:53:08 57014 [Note] InnoDB: Tablespace and datafile system tables created.
2018-11-07 12:53:08 57014 [Note] InnoDB: Waiting for purge to start
2018-11-07 12:53:08 57014 [Note] InnoDB: 5.6.42 started; log sequence number 0
2018-11-07 12:53:10 57014 [Note] Binlog end
2018-11-07 12:53:10 57014 [Note] InnoDB: FTS optimize thread exiting.
2018-11-07 12:53:10 57014 [Note] InnoDB: Starting shutdown...
2018-11-07 12:53:12 57014 [Note] InnoDB: Shutdown completed; log sequence number 1625977
OK
Filling help tables...2018-11-07 12:53:12 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-11-07 12:53:12 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
2018-11-07 12:53:12 0 [Note] ./bin/mysqld (mysqld 5.6.42) starting as process 57036 ...
2018-11-07 12:53:12 57036 [Note] InnoDB: Using atomics to ref count buffer pool pages
2018-11-07 12:53:12 57036 [Note] InnoDB: The InnoDB memory heap is disabled
2018-11-07 12:53:12 57036 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2018-11-07 12:53:12 57036 [Note] InnoDB: Memory barrier is not used
2018-11-07 12:53:12 57036 [Note] InnoDB: Compressed tables use zlib 1.2.11
2018-11-07 12:53:12 57036 [Note] InnoDB: Using Linux native AIO
2018-11-07 12:53:12 57036 [Note] InnoDB: Using CPU crc32 instructions
2018-11-07 12:53:12 57036 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2018-11-07 12:53:12 57036 [Note] InnoDB: Completed initialization of buffer pool
2018-11-07 12:53:12 57036 [Note] InnoDB: Highest supported file format is Barracuda.
2018-11-07 12:53:12 57036 [Note] InnoDB: 128 rollback segment(s) are active.
2018-11-07 12:53:12 57036 [Note] InnoDB: Waiting for purge to start
2018-11-07 12:53:12 57036 [Note] InnoDB: 5.6.42 started; log sequence number 1625977
2018-11-07 12:53:13 57036 [Note] Binlog end
2018-11-07 12:53:13 57036 [Note] InnoDB: FTS optimize thread exiting.
2018-11-07 12:53:13 57036 [Note] InnoDB: Starting shutdown...
2018-11-07 12:53:14 57036 [Note] InnoDB: Shutdown completed; log sequence number 1625987
OK
To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
./bin/mysqladmin -u root password 'new-password'
./bin/mysqladmin -u root -h localhost.localdomain password 'new-password'
Alternatively you can run:
./bin/mysql_secure_installation
which will also give you the option of removing the test
databases and anonymous user created by default. This is
strongly recommended for production servers.
See the manual for more instructions.
You can start the MySQL daemon with:
cd . ; ./bin/mysqld_safe &
You can test the MySQL daemon with mysql-test-run.pl
cd mysql-test ; perl mysql-test-run.pl
Please report any problems at http://bugs.mysql.com/
The latest information about MySQL is available on the web at
http://www.mysql.com
Support MySQL by buying support/licenses at http://shop.mysql.com
New default config file was created as ./my.cnf and
will be used by default by the server when you start it.
You may edit this file to change server settings
7.将 /usr/local/mysql 下的所有文件的组和用户改回 root,data 目录的组和用户为 mysql
修改当前目录拥有者为root用户:执行命令 chown -R root:root ./
修改当前data目录拥有者为mysql用户:执行命令 chown -R mysql:mysql data
[root@localhost mysql]# chown -R root:root ./
[root@localhost mysql]# ll
总用量 52
drwxr-xr-x. 2 root root 4096 11月 7 12:08 bin
-rw-r--r--. 1 root root 17987 11月 7 12:07 COPYING
drwxr-xr-x. 5 root root 110 11月 7 12:53 data
drwxr-xr-x. 2 root root 55 11月 7 12:07 docs
drwxr-xr-x. 3 root root 4096 11月 7 12:07 include
drwxr-xr-x. 3 root root 4096 11月 7 12:08 lib
drwxr-xr-x. 4 root root 30 11月 7 12:07 man
-rw-r--r--. 1 root root 943 11月 7 12:53 my.cnf
drwxr-xr-x. 10 root root 4096 11月 7 12:07 mysql-test
-rw-r--r--. 1 root root 2496 11月 7 12:08 README
drwxr-xr-x. 2 root root 30 11月 7 12:07 scripts
drwxr-xr-x. 28 root root 4096 11月 7 12:08 share
drwxr-xr-x. 4 root root 4096 11月 7 12:08 sql-bench
drwxr-xr-x. 2 root root 136 11月 7 12:07 support-files
[root@localhost mysql]# chown -R mysql:mysql data
[root@localhost mysql]# ll
总用量 52
drwxr-xr-x. 2 root root 4096 11月 7 12:08 bin
-rw-r--r--. 1 root root 17987 11月 7 12:07 COPYING
drwxr-xr-x. 5 mysql mysql 110 11月 7 12:53 data
drwxr-xr-x. 2 root root 55 11月 7 12:07 docs
drwxr-xr-x. 3 root root 4096 11月 7 12:07 include
drwxr-xr-x. 3 root root 4096 11月 7 12:08 lib
drwxr-xr-x. 4 root root 30 11月 7 12:07 man
-rw-r--r--. 1 root root 943 11月 7 12:53 my.cnf
drwxr-xr-x. 10 root root 4096 11月 7 12:07 mysql-test
-rw-r--r--. 1 root root 2496 11月 7 12:08 README
drwxr-xr-x. 2 root root 30 11月 7 12:07 scripts
drwxr-xr-x. 28 root root 4096 11月 7 12:08 share
drwxr-xr-x. 4 root root 4096 11月 7 12:08 sql-bench
drwxr-xr-x. 2 root root 136 11月 7 12:07 support-files
[root@localhost mysql]# whereis mysql
mysql: /usr/lib64/mysql /usr/local/mysql
[root@localhost mysql]# find / -name mysql
find: ‘/run/user/1000/gvfs’: 权限不够
/etc/selinux/targeted/active/modules/100/mysql
/usr/lib64/mysql
/usr/local/mysql
/usr/local/mysql/data/mysql
/usr/local/mysql/include/mysql
/usr/local/mysql/bin/mysql
/home/vicky/mysql-5.6.42-linux-glibc2.12-x86_64/include/mysql
/home/vicky/mysql-5.6.42-linux-glibc2.12-x86_64/bin/mysql
8.配置运行
[root@localhost bin]# pwd
/usr/local/mysql/bin
[root@localhost bin]# ./mysqld --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
9.启动 mysqld 服务
报错一:
[root@localhost init.d]# service mysqld start
Unit mysqld.service could not be found.
2018-11-07 13:04:51 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-11-07 13:04:51 0 [Note] --secure-file-priv is set to NULL. Operations related to importing and exporting data are disabled
2018-11-07 13:04:51 0 [Note] /etc/init.d/mysqld (mysqld 5.6.42) starting as process 57480 ...
2018-11-07 13:04:51 57480 [ERROR] Fatal error: Please read "Security" section of the manual to find out how to run mysqld as root!
2018-11-07 13:04:51 57480 [ERROR] Aborting
2018-11-07 13:04:51 57480 [Note] Binlog end
2018-11-07 13:04:51 57480 [Note] /etc/init.d/mysqld: Shutdown complete
解决方法:在 /etc/my.cnf 中添加了 user = mysql
报错二:之后还是报错:
/etc/init.d/mysqld: Too many arguments (first extra is 'start').
Use --verbose --help to get a list of available options
2018-11-07 13:34:01 3914 [ERROR] Aborting
解决方法:将 ./support-files/mysql.server 拷贝到 /etc/rc.d/init.d 之下,并重命名为 mysqld,之前的步骤是直接将 /usr/local/mysql/bin/mysqld 拷贝到了 /etc/rc.d/init.d 目录下。
[root@localhost mysql]# cp ./support-files/mysql.server /etc/rc.d/init.d/mysqld #缺少这一步
cp:是否覆盖"/etc/rc.d/init.d/mysqld"? y
[root@localhost mysql]# cd /etc/rc.d/init.d/
[root@localhost init.d]# ll
总用量 44
-rw-r--r--. 1 root root 15131 9月 12 2016 functions
-rwxr-xr-x. 1 root root 10565 11月 7 14:15 mysqld
-rwxr-xr-x. 1 root root 2989 9月 12 2016 netconsole
-rwxr-xr-x. 1 root root 6643 9月 12 2016 network
-rw-r--r--. 1 root root 1160 11月 7 2016 README
10.再次启动服务
[root@localhost init.d]# service mysql start
Redirecting to /bin/systemctl start mysql.service
Failed to start mysql.service: Unit not found.
[root@localhost init.d]# service mysqld start
Starting MySQL...................................................................................................... ERROR! The server quit without updating PID file (/usr/local/mysql/data/localhost.localdomain.pid).
[root@localhost init.d]#
报错三:ERROR! The server quit without updating PID file (/usr/local/mysql/data/localhost.localdomain.pid).
原因:selinux惹的祸,如果是centos系统,默认会开启selinux。
解决方法:
关闭 selinux,打开/etc/selinux/config,把 SELINUX=enforcing 改为 SELINUX=disabled 后存盘退出重启机器。
11.再次启动,ok了。
12.连接 mysql 数据库。
报错四:找不到 mysql 命令
原因:没有添加环境变量中
解决方法: 编辑/etc/profile文件:将 mysql 的路径 /usr/local/mysql/bin 添加到系统变量。
具体操作: vi /etc/profile
在文件最后添加如下两行:
PATH=$PATH:/usr/local/mysql/bin
export PATH
执行下面的命令使所做的更改生效:
source /etc/profile
13.再次连接
[vicky@localhost ~]$ mysql -uroot -p
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
查看 /tmp 路径下 没有 mysql.sock
[root@localhost support-files]# cd /tmp
[root@localhost tmp]# ls
anaconda.log
hsperfdata_root
hsperfdata_vicky
ifcfg.log
ks-script-OnfMKx
packaging.log
program.log
sensitive-info.log
ssh-lp2CWKCwhWAw
storage.log
systemd-private-ac3f666b0c274c9b9692e53a709ebd63-colord.service-QuGFzU
systemd-private-ac3f666b0c274c9b9692e53a709ebd63-cups.service-QNieXU
systemd-private-ac3f666b0c274c9b9692e53a709ebd63-rtkit-daemon.service-HrZuGY
systemd-private-ac3f666b0c274c9b9692e53a709ebd63-vmtoolsd.service-QP2Dot
tracker-extract-files.1000
VMwareDnD
yum.log
yum_save_tx.2018-11-07.11-25.r9BWym.yumtx
查看程序是否启动,原来没有起~~~~~~~~
[root@localhost init.d]# ps -ef |grep mysqld
root 3746 3587 0 14:41 pts/0 00:00:00 grep --color=auto mysqld
[root@localhost init.d]# ps -ef |grep mysql
root 3751 3587 0 14:41 pts/0 00:00:00 grep --color=auto mysql
重新启动 mysql 服务:
[root@localhost init.d]# service mysqld start
Starting MySQL..... SUCCESS!
进入到 /tmp 路径下,可以发现已经有了 mysql.sock
[root@localhost init.d]# cd /tmp
[root@localhost tmp]# ll
总用量 848
-rw-r--r--. 1 root root 1757 11月 7 2018 anaconda.log
drwxr-xr-x. 2 root root 18 11月 7 2018 hsperfdata_root
drwxr-xr-x. 2 vicky vicky 6 11月 7 11:25 hsperfdata_vicky
-rw-r--r--. 1 root root 166 11月 7 2018 ifcfg.log
-rwx------. 1 root root 836 11月 7 2018 ks-script-OnfMKx
srwxrwxrwx 1 mysql mysql 0 11月 7 14:42 mysql.sock
-rw-r--r--. 1 root root 0 11月 7 2018 packaging.log
-rw-r--r--. 1 root root 0 11月 7 2018 program.log
-rw-r--r--. 1 root root 0 11月 7 2018 sensitive-info.log
drwx------ 2 vicky vicky 24 11月 7 14:33 ssh-lp2CWKCwhWAw
-rw-r--r--. 1 root root 0 11月 7 2018 storage.log
drwx------ 3 root root 17 11月 7 14:29 systemd-private-ac3f666b0c274c9b9692e53a709ebd63-colord.service-QuGFzU
drwx------ 3 root root 17 11月 7 14:29 systemd-private-ac3f666b0c274c9b9692e53a709ebd63-cups.service-QNieXU
drwx------ 3 root root 17 11月 7 14:29 systemd-private-ac3f666b0c274c9b9692e53a709ebd63-rtkit-daemon.service-HrZuGY
drwx------ 3 root root 17 11月 7 14:29 systemd-private-ac3f666b0c274c9b9692e53a709ebd63-vmtoolsd.service-QP2Dot
drwx------. 2 vicky vicky 6 11月 7 11:22 tracker-extract-files.1000
drwxrwxrwt. 3 vicky vicky 22 11月 7 12:04 VMwareDnD
-rw-------. 1 root root 0 11月 7 2018 yum.log
-rw-------. 1 root root 852461 11月 7 11:25 yum_save_tx.2018-11-07.11-25.r9BWym.yumtx
14.连接数据库,默认的 root 用户密码为空,在输入密码的地方,什么都不输入直接回车。
[root@localhost tmp]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.42 MySQL Community Server (GPL)
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;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.30 sec)
查看 root 用户的信息:
mysql> select host,user,password from mysql.user where user ='root'l
-> ;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'l' at line 1
mysql> select host,user,password from mysql.user where user ='root';
+-----------------------+------+----------+
| host | user | password |
+-----------------------+------+----------+
| localhost | root | |
| localhost.localdomain | root | |
| 127.0.0.1 | root | |
| ::1 | root | |
+-----------------------+------+----------+
4 rows in set (0.12 sec)
修改 root 用户密码为 root :
mysql> update mysql.user set password=PASSWORD('root') where user='root';
Query OK, 4 rows affected (0.14 sec)
Rows matched: 4 Changed: 4 Warnings: 0
mysql> flush privilege;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'privilege' at line 1
mysql> flush privileges;
Query OK, 0 rows affected (0.07 sec)
mysql> quit
Bye
重新登录 mysql ,在输入密码的地方输入 root, 登录成功。
[root@localhost tmp]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.42 MySQL Community Server (GPL)
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>
终于搞定!!!!
声明:
本博客内容仅是个人学习,解决问题的记录,如有错误,欢迎指正,如有侵权请告知修改。