扫二维码与项目经理沟通
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流
让客户满意是我们工作的目标,不断超越客户的期望值来自于我们对这个行业的热爱。我们立志把好的技术通过有效、简单的方式提供给客户,将通过不懈努力成为客户在信息化领域值得信任、有价值的长期合作伙伴,公司提供的服务项目有:域名与空间、虚拟主机、营销软件、网站建设、辽宁网站维护、网站推广。
安装MySQL-5.6.36-linux-glibc2.5-x86_64.tar.gz
0、首先解压
[root@VM_83_223_centos ~]# tar zxvf mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz
1、创建mysql用户
[root@VM_83_223_centos scripts]# useradd mysql
2、设置mysql用户的密码
[root@VM_83_223_centos scripts]# passwd mysql
Changing password for user mysql.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.
3、设置/usr/local/mysql目录的权限
[root@VM_83_223_centos local]# mkdir mysql
[root@VM_83_223_centos local]#
[root@VM_83_223_centos local]# chown -R mysql:mysql mysql/
4、执行mysql安装脚本,报错
[root@VM_83_223_centos scripts]# ./mysql_install_db
FATAL ERROR: please install the following Perl modules before executing ./mysql_install_db:
Data::Dumper
解决方法:
安装autoconf库,此包安装时会安装Data::Dumper模块
[root@VM_83_223_centos scripts]# yum install autoconf
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package autoconf.noarch 0:2.69-11.el7 will be installed
--> Processing Dependency: m4 >= 1.4.14 for package: autoconf-2.69-11.el7.noarch
--> Processing Dependency: perl(Data::Dumper) for package: autoconf-2.69-11.el7.noarch
--> Running transaction check
---> Package m4.x86_64 0:1.4.16-10.el7 will be installed
---> Package perl-Data-Dumper.x86_64 0:2.145-3.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
===================================================================================================================================================================
Package Arch Version Repository Size
===================================================================================================================================================================
Installing:
autoconf noarch 2.69-11.el7 os 701 k
Installing for dependencies:
m4 x86_64 1.4.16-10.el7 os 256 k
perl-Data-Dumper x86_64 2.145-3.el7 os 47 k
Transaction Summary
===================================================================================================================================================================
Install 1 Package (+2 Dependent packages)
Total download size: 1.0 M
Installed size: 2.8 M
Is this ok [y/d/N]: y
Downloading packages:
(1/3): m4-1.4.16-10.el7.x86_64.rpm | 256 kB 00:00:00
(2/3): perl-Data-Dumper-2.145-3.el7.x86_64.rpm | 47 kB 00:00:00
(3/3): autoconf-2.69-11.el7.noarch.rpm | 701 kB 00:00:00
-------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total 5.7 MB/s | 1.0 MB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : m4-1.4.16-10.el7.x86_64 1/3
Installing : perl-Data-Dumper-2.145-3.el7.x86_64 2/3
Installing : autoconf-2.69-11.el7.noarch 3/3
Verifying : perl-Data-Dumper-2.145-3.el7.x86_64 1/3
Verifying : m4-1.4.16-10.el7.x86_64 2/3
Verifying : autoconf-2.69-11.el7.noarch 3/3
Installed:
autoconf.noarch 0:2.69-11.el7
Dependency Installed:
m4.x86_64 0:1.4.16-10.el7 perl-Data-Dumper.x86_64 0:2.145-3.el7
Complete!
5、安装成功后,再次执行安装脚本,又出现报错
root@VM_83_223_centos scripts]# ./mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
FATAL ERROR: Could not find ./bin/my_print_defaults
If you compiled from source, you need to run 'make install' to
copy the software into the correct location ready for operation.
If you are using a binary release, you must either be at the top
level of the extracted archive, or pass the --basedir option
pointing to that location.
root@VM_83_223_centos scripts]# ./mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
FATAL ERROR: Could not find ./bin/my_print_defaults
If you compiled from source, you need to run 'make install' to
copy the software into the correct location ready for operation.
If you are using a binary release, you must either be at the top
level of the extracted archive, or pass the --basedir option
pointing to that location.
按照报错信息,去mysql安装目录的bin目下查找是否有my_print_defaults,发现有这个文件
[root@VM_83_223_centos ~]# ls mysql-5.6.36-linux-glibc2.5-x86_64/bin/
innochecksum mysql mysql_client_test mysqld_multi mysqlhotcopy mysqltest replace
msql2mysql mysqlaccess mysql_client_test_embedded mysqld_safe mysqlimport mysqltest_embedded resolveip
myisamchk mysqlaccess.conf mysql_config mysqldump mysql_plugin mysql_tzinfo_to_sql resolve_stack_dump
myisam_ftdump mysqladmin mysql_config_editor mysqldumpslow mysql_secure_installation mysql_upgrade
myisamlog mysqlbinlog mysql_convert_table_format mysql_embedded mysql_setpermission mysql_waitpid
myisampack mysqlbug mysqld mysql_find_rows mysqlshow mysql_zap
my_print_defaults mysqlcheck mysqld-debug mysql_fix_extensions mysqlslap perror
看来其实不是没有这个文件,不是这个问题。认真查看报错信息,可注意到那个路径是相对路径,是以mysql的安装目录为起始。而初始化则是进去初始化脚本目录里运行脚本,而在这个目录下不会有./bin/my_print_defaults的。所以回到安装目录以相对路径去执行初始化脚本。
解决方法:
(1)首先将解压后的所有文件都复制到mysql的安装目录下/usr/bin/mysql
[root@VM_83_223_centos ~]# cp -R mysql-5.6.36-linux-glibc2.5-x86_64/* /usr/local/mysql/
[root@VM_83_223_centos ~]# cd /usr/local/
[root@VM_83_223_centos local]# cd mysql/
[root@VM_83_223_centos mysql]# ll
total 68
drwxr-xr-x 2 root root 4096 Mar 27 20:59 bin
-rw-r--r-- 1 root root 17987 Mar 27 20:59 COPYING
drwxr-xr-x 3 root root 4096 Mar 27 20:59 data
drwxr-xr-x 2 root root 4096 Mar 27 20:59 docs
drwxr-xr-x 3 root root 4096 Mar 27 20:59 include
drwxr-xr-x 3 root root 4096 Mar 27 20:59 lib
drwxr-xr-x 4 root root 4096 Mar 27 20:59 man
drwxr-xr-x 10 root root 4096 Mar 27 21:00 mysql-test
-rw-r--r-- 1 root root 2496 Mar 27 20:59 README
drwxr-xr-x 2 root root 4096 Mar 27 21:00 scripts
drwxr-xr-x 28 root root 4096 Mar 27 21:00 share
drwxr-xr-x 4 root root 4096 Mar 27 21:00 sql-bench
drwxr-xr-x 2 root root 4096 Mar 27 21:00 support-files
(2)采用绝对路径执行安装脚本
[root@VM_83_223_centos mysql]#./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
Installing MySQL system tables...2018-03-27 21:01:02 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-03-27 21:01:02 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
2018-03-27 21:01:02 0 [Note] /usr/local/mysql/bin/mysqld (mysqld 5.6.36) starting as process 20251 ...
2018-03-27 21:01:02 20251 [Note] InnoDB: Using atomics to ref count buffer pool pages
2018-03-27 21:01:02 20251 [Note] InnoDB: The InnoDB memory heap is disabled
2018-03-27 21:01:02 20251 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2018-03-27 21:01:02 20251 [Note] InnoDB: Memory barrier is not used
2018-03-27 21:01:02 20251 [Note] InnoDB: Compressed tables use zlib 1.2.3
2018-03-27 21:01:02 20251 [Note] InnoDB: Using Linux native AIO
2018-03-27 21:01:02 20251 [Note] InnoDB: Using CPU crc32 instructions
2018-03-27 21:01:02 20251 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2018-03-27 21:01:02 20251 [Note] InnoDB: Completed initialization of buffer pool
2018-03-27 21:01:02 20251 [Note] InnoDB: The first specified data file ./ibdata1 did not exist: a new database to be created!
2018-03-27 21:01:02 20251 [Note] InnoDB: Setting file ./ibdata1 size to 12 MB
2018-03-27 21:01:02 20251 [Note] InnoDB: Database physically writes the file full: wait...
2018-03-27 21:01:02 20251 [Note] InnoDB: Setting log file ./ib_logfile101 size to 48 MB
2018-03-27 21:01:03 20251 [Note] InnoDB: Setting log file ./ib_logfile1 size to 48 MB
2018-03-27 21:01:03 20251 [Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0
2018-03-27 21:01:03 20251 [Warning] InnoDB: New log files created, LSN=45781
2018-03-27 21:01:03 20251 [Note] InnoDB: Doublewrite buffer not found: creating new
2018-03-27 21:01:03 20251 [Note] InnoDB: Doublewrite buffer created
2018-03-27 21:01:03 20251 [Note] InnoDB: 128 rollback segment(s) are active.
2018-03-27 21:01:03 20251 [Warning] InnoDB: Creating foreign key constraint system tables.
2018-03-27 21:01:03 20251 [Note] InnoDB: Foreign key constraint system tables created
2018-03-27 21:01:03 20251 [Note] InnoDB: Creating tablespace and datafile system tables.
2018-03-27 21:01:03 20251 [Note] InnoDB: Tablespace and datafile system tables created.
2018-03-27 21:01:03 20251 [Note] InnoDB: Waiting for purge to start
2018-03-27 21:01:03 20251 [Note] InnoDB: 5.6.36 started; log sequence number 0
2018-03-27 21:01:05 20251 [Note] Binlog end
2018-03-27 21:01:05 20251 [Note] InnoDB: FTS optimize thread exiting.
2018-03-27 21:01:05 20251 [Note] InnoDB: Starting shutdown...
2018-03-27 21:01:06 20251 [Note] InnoDB: Shutdown completed; log sequence number 1625977
OK
Filling help tables...2018-03-27 21:01:06 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-03-27 21:01:06 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
2018-03-27 21:01:06 0 [Note] /usr/local/mysql/bin/mysqld (mysqld 5.6.36) starting as process 20274 ...
2018-03-27 21:01:06 20274 [Note] InnoDB: Using atomics to ref count buffer pool pages
2018-03-27 21:01:06 20274 [Note] InnoDB: The InnoDB memory heap is disabled
2018-03-27 21:01:06 20274 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2018-03-27 21:01:06 20274 [Note] InnoDB: Memory barrier is not used
2018-03-27 21:01:06 20274 [Note] InnoDB: Compressed tables use zlib 1.2.3
2018-03-27 21:01:06 20274 [Note] InnoDB: Using Linux native AIO
2018-03-27 21:01:06 20274 [Note] InnoDB: Using CPU crc32 instructions
2018-03-27 21:01:06 20274 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2018-03-27 21:01:06 20274 [Note] InnoDB: Completed initialization of buffer pool
2018-03-27 21:01:06 20274 [Note] InnoDB: Highest supported file format is Barracuda.
2018-03-27 21:01:06 20274 [Note] InnoDB: 128 rollback segment(s) are active.
2018-03-27 21:01:06 20274 [Note] InnoDB: Waiting for purge to start
2018-03-27 21:01:06 20274 [Note] InnoDB: 5.6.36 started; log sequence number 1625977
2018-03-27 21:01:06 20274 [Note] Binlog end
2018-03-27 21:01:06 20274 [Note] InnoDB: FTS optimize thread exiting.
2018-03-27 21:01:06 20274 [Note] InnoDB: Starting shutdown...
2018-03-27 21:01:08 20274 [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:
/usr/local/mysql/bin/mysqladmin -u root password 'new-password'
/usr/local/mysql/bin/mysqladmin -u root -h VM_83_223_centos password 'new-password'
Alternatively you can run:
/usr/local/mysql/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 . ; /usr/local/mysql/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 /usr/local/mysql/my.cnf and
will be used by default by the server when you start it.
You may edit this file to change server settings
WARNING: Default config file /etc/my.cnf exists on the system
This file will be read by default by the MySQL server
If you do not want to use this, either remove it, or use the
--defaults-file argument to mysqld_safe when starting the server
6、修改相关的配置文件
[root@VM_83_223_centos mysql]# ll
total 72
drwxr-xr-x 2 root root 4096 Mar 27 20:59 bin
-rw-r--r-- 1 root root 17987 Mar 27 20:59 COPYING
drwxr-xr-x 5 mysql mysql 4096 Mar 27 21:01 data
drwxr-xr-x 2 root root 4096 Mar 27 20:59 docs
drwxr-xr-x 3 root root 4096 Mar 27 20:59 include
drwxr-xr-x 3 root root 4096 Mar 27 20:59 lib
drwxr-xr-x 4 root root 4096 Mar 27 20:59 man
-rw-r--r-- 1 root root 943 Mar 27 21:01 my.cnf
drwxr-xr-x 10 root root 4096 Mar 27 21:00 mysql-test
-rw-r--r-- 1 root root 2496 Mar 27 20:59 README
drwxr-xr-x 2 root root 4096 Mar 27 21:00 scripts
drwxr-xr-x 28 root root 4096 Mar 27 21:00 share
drwxr-xr-x 4 root root 4096 Mar 27 21:00 sql-bench
drwxr-xr-x 2 root root 4096 Mar 27 21:00 support-files
[root@VM_83_223_centos mysql]# cd support-files/
[root@VM_83_223_centos support-files]# ll
total 32
-rwxr-xr-x 1 root root 1153 Mar 27 21:00 binary-configure
-rw-r--r-- 1 root root 773 Mar 27 21:00 magic
-rw-r--r-- 1 root root 1126 Mar 27 21:00 my-default.cnf
-rwxr-xr-x 1 root root 1061 Mar 27 21:00 mysqld_multi.server
-rwxr-xr-x 1 root root 894 Mar 27 21:00 mysql-log-rotate
-rwxr-xr-x 1 root root 10565 Mar 27 21:00 mysql.server
[root@VM_83_223_centos support-files]# cp my-default.cnf /etc/my.cnf
cp: overwrite ‘/etc/my.cnf’? y
[root@VM_83_223_centos support-files]# cp mysql.server /etc/init.d/mysql
[root@VM_83_223_centos mysql]# ll
total 72
drwxr-xr-x 2 root root 4096 Mar 27 20:59 bin
-rw-r--r-- 1 root root 17987 Mar 27 20:59 COPYING
drwxr-xr-x 5 mysql mysql 4096 Mar 27 21:01 data
drwxr-xr-x 2 root root 4096 Mar 27 20:59 docs
drwxr-xr-x 3 root root 4096 Mar 27 20:59 include
drwxr-xr-x 3 root root 4096 Mar 27 20:59 lib
drwxr-xr-x 4 root root 4096 Mar 27 20:59 man
-rw-r--r-- 1 root root 943 Mar 27 21:01 my.cnf
drwxr-xr-x 10 root root 4096 Mar 27 21:00 mysql-test
-rw-r--r-- 1 root root 2496 Mar 27 20:59 README
drwxr-xr-x 2 root root 4096 Mar 27 21:00 scripts
drwxr-xr-x 28 root root 4096 Mar 27 21:00 share
drwxr-xr-x 4 root root 4096 Mar 27 21:00 sql-bench
drwxr-xr-x 2 root root 4096 Mar 27 21:00 support-files
[root@VM_83_223_centos support-files]#vim /etc/init.d/mysql #若mysql的安装目录是/usr/local/mysql,则可省略此步
修改文件中的两个变更值
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
7、配置环境变量
[root@VM_83_223_centos support-files]#vim /etc/profile
添加下面两行
export MYSQL_HOME=/usr/local/mysql
export PATH=$MYSQL_HOME/bin:$PATH
使修改生效
[root@VM_83_223_centos support-files]#source /etc/profile
8、配置服务,启动服务并设置为自启动
[root@VM_83_223_centos support-files]# chkconfig --add mysql
[root@VM_83_223_centos support-files]#
[root@VM_83_223_centos support-files]# systemctl status mysql.service
● mysql.service - LSB: start and stop MySQL
Loaded: loaded (/etc/rc.d/init.d/mysql; bad; vendor preset: disabled)
Active: inactive (dead)
Docs: man:systemd-sysv-generator(8)
[root@VM_83_223_centos support-files]#
[root@VM_83_223_centos support-files]# systemctl start mysql.service
[root@VM_83_223_centos support-files]#
[root@VM_83_223_centos support-files]# systemctl status mysql.service
● mysql.service - LSB: start and stop MySQL
Loaded: loaded (/etc/rc.d/init.d/mysql; bad; vendor preset: disabled)
Active: active (running) since Tue 2018-03-27 21:12:07 CST; 2s ago
Docs: man:systemd-sysv-generator(8)
Process: 21092 ExecStart=/etc/rc.d/init.d/mysql start (code=exited, status=0/SUCCESS)
CGroup: /system.slice/mysql.service
├─21097 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/usr/local/mysql/data --pid-file=/usr/local/mysql/data/VM_83_223_centos.pid
└─21204 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql ...
Mar 27 21:12:06 VM_83_223_centos systemd[1]: Starting LSB: start and stop MySQL...
Mar 27 21:12:06 VM_83_223_centos mysql[21092]: Starting MySQL.Logging to '/usr/local/mysql/data/VM_83_223_centos.err'.
Mar 27 21:12:07 VM_83_223_centos mysql[21092]: SUCCESS!
Mar 27 21:12:07 VM_83_223_centos systemd[1]: Started LSB: start and stop MySQL.
[root@VM_83_223_centos support-files]# systemctl enable mysql.service
mysql.service is not a native service, redirecting to /sbin/chkconfig.
Executing /sbin/chkconfig mysql on
[root@VM_83_223_centos support-files]#
[root@VM_83_223_centos support-files]# /sbin/chkconfig mysql on
[root@VM_83_223_centos support-files]#
[root@VM_83_223_centos support-files]# chkconfig --list mysql
Note: This output shows SysV services only and does not include native
systemd services. SysV configuration data might be overridden by native
systemd configuration.
If you want to list systemd services use 'systemctl list-unit-files'.
To see services enabled on particular target use
'systemctl list-dependencies [target]'.
mysql 0:off 1:off 2:on 3:on 4:on 5:on 6:off
9、设置root用户的密码
[root@VM_83_223_centos support-files]# /usr/local/mysql/bin/mysqladmin -u root password 'qcloud@2018'
Warning: Using a password on the command line interface can be insecure.
10、登录授权
[root@VM_83_223_centos support-files]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.6.36 MySQL Community Server (GPL)
Copyright (c) 2000, 2017, 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> select version();
+-----------+
| version() |
+-----------+
| 5.6.36 |
+-----------+
1 row in set (0.00 sec)
mysql> select host,user from mysql.user;
+---------------------+------+
| host | user |
+---------------------+------+
| 127.0.0.1 | root |
| ::1 | root |
| localhost | |
| localhost | root |
| vm\_83\_223\_centos | |
| vm\_83\_223\_centos | root |
+---------------------+------+
6 rows in set (0.00 sec)
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'qcloud@2018' WITH GRANT OPTION;
Query OK, 0 rows affected (0.00 sec)
mysql> select host,user from mysql.user;
+---------------------+------+
| host | user |
+---------------------+------+
| % | root |
| 127.0.0.1 | root |
| ::1 | root |
| localhost | |
| localhost | root |
| vm\_83\_223\_centos | |
| vm\_83\_223\_centos | root |
+---------------------+------+
7 rows in set (0.00 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
作者:SEian.G(苦练七十二变,笑对八十一难)
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流