注:
按照上一个安装说明操作,会出现一些问题。
比如,自动安装的mysql版本很旧,5.1.0x版本的,官网的Mysql已经是 5.6.x版本了。
如果坚持安装最新版本,在MYSQL官网下载rpm-.tar安装包,Linux 64位版本的大小大约300MB左右。
1.下载:
MySQL-5.6.26-1.linux_glibc2.5.x86_64.rpm-bundle.tar
下载地址:
http://dev.mysql.com/downloads/file.php?id=458430
其他安装包下载页面:
http://dev.mysql.com/downloads/mysql/
2.检查是否安装:
rpm -qa | grep -i mysql
显示已经安装了:
[hadoop@Slave1 ~]$ rpm -qa | grep -i mysql
mysql-libs-5.1.71-1.el6.x86_64
[hadoop@Slave1 ~]$
3.删除已安装软件:
rpm -e mysql-libs-5.1.71-1.el6.x86_64 --nodeps
显示信息如下:
[hadoop@Slave1 ~]$ rpm -e mysql-libs-5.1.71-1.el6.x86_64 --nodeps
error: can't create transaction lock on /var/lib/rpm/.rpm.lock (Permission denied)
[hadoop@Slave1 ~]$ su
Password:
[root@Slave1 hadoop]# rpm -e mysql-libs-5.1.71-1.el6.x86_64 --nodeps
[root@Slave1 hadoop]#
刚开始在hadoop用户下操作失败,换成root用户成功
4.查找是否有残留:
find / -name *mysql*
显示信息如下:
[root@Slave1 hadoop]# find / -name *mysql*
/etc/selinux/targeted/modules/active/modules/mysql.pp
/var/lib/yum/yumdb/m/b642f65e3df41063e068158061ae2e08f22e3dad-mysql-libs-5.1.71-1.el6-x86_64
/usr/share/doc/rsyslog-5.8.10/ommysql.html
/usr/share/doc/rsyslog-5.8.10/rsyslog_mysql.html
/usr/share/man/man5/mysql_table.5.gz
/usr/share/selinux/devel/include/services/mysql.if
/usr/share/selinux/targeted/mysql.pp.bz2
/usr/share/vim/vim72/syntax/mysql.vim
/usr/lib/python2.6/site-packages/sos/plugins/mysql.py
/usr/lib/python2.6/site-packages/sos/plugins/mysql.pyo
/usr/lib/python2.6/site-packages/sos/plugins/mysql.pyc
/selinux/booleans/allow_user_mysql_connect
/selinux/booleans/mysql_connect_any
[root@Slave1 hadoop]#
还是有残留
5.再次检查是否已安装
[root@Slave1 hadoop]# rpm -qa | grep -i mysql
[root@Slave1 hadoop]#
6.检查是否有用户和组
[root@Slave1 hadoop]# nl /etc/group | grep mysql
[root@Slave1 hadoop]# nl /etc/shadow | grep mysql
[root@Slave1 hadoop]#
没有反应
7.解压缩包
[root@Slave1 hadoop]# tar -zxvf MySQL-5.6.26-1.linux_glibc2.5.x86_64.rpm-bundle.tar -C /usr/local/mysql
gzip: stdin: not in gzip format
tar: Child returned status 1
tar: Error is not recoverable: exiting now
[root@Slave1 hadoop]# tar -xvf MySQL-5.6.26-1.linux_glibc2.5.x86_64.rpm-bundle.tar -C /usr/local/mysql
MySQL-server-5.6.26-1.linux_glibc2.5.x86_64.rpm
MySQL-shared-5.6.26-1.linux_glibc2.5.x86_64.rpm
MySQL-devel-5.6.26-1.linux_glibc2.5.x86_64.rpm
MySQL-client-5.6.26-1.linux_glibc2.5.x86_64.rpm
MySQL-shared-compat-5.6.26-1.linux_glibc2.5.x86_64.rpm
MySQL-embedded-5.6.26-1.linux_glibc2.5.x86_64.rpm
MySQL-test-5.6.26-1.linux_glibc2.5.x86_64.rpm
[root@Slave1 hadoop]#
tar后面是-zxvf报错,是-xvf则正确
关于tar命令:
tar cvf 备份文件.tar 备份文件或目录
tar czvf 备份文件.tar.gz 备份文件或目录
tar xzvf 备份文件.tar.gz 备份文件或目录 -C 解压到的目录
c:(create)建立新的备份文件
v:(verbose)显示指令的执行过程
f:(file)置顶备份文件
z:(gzip或ungzip)通过gzip指令处理备份文件
x:从备份文件中还原文件
8.继续安装:
[root@Slave1 hadoop]# cd /usr/local/mysql/
[root@Slave1 mysql]# rpm -ivh MySQL-server-5.6.26-1.linux_glibc2.5.x86_64.rpm
warning: MySQL-server-5.6.26-1.linux_glibc2.5.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ########################################### [100%]
1:MySQL-server ########################################### [100%]
warning: user mysql does not exist - using root
warning: group mysql does not exist - using root
2015-09-18 00:07:57 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2015-09-18 00:07:57 0 [Note] /usr/sbin/mysqld (mysqld 5.6.26) starting as process 8732 ...
2015-09-18 00:07:58 8732 [Note] InnoDB: Using atomics to ref count buffer pool pages
2015-09-18 00:07:58 8732 [Note] InnoDB: The InnoDB memory heap is disabled
2015-09-18 00:07:58 8732 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2015-09-18 00:07:58 8732 [Note] InnoDB: Memory barrier is not used
2015-09-18 00:07:58 8732 [Note] InnoDB: Compressed tables use zlib 1.2.3
2015-09-18 00:07:58 8732 [Note] InnoDB: Using Linux native AIO
2015-09-18 00:07:58 8732 [Note] InnoDB: Using CPU crc32 instructions
2015-09-18 00:07:58 8732 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2015-09-18 00:07:58 8732 [Note] InnoDB: Completed initialization of buffer pool
2015-09-18 00:07:58 8732 [Note] InnoDB: The first specified data file ./ibdata1 did not exist: a new database to be created!
2015-09-18 00:07:58 8732 [Note] InnoDB: Setting file ./ibdata1 size to 12 MB
2015-09-18 00:07:58 8732 [Note] InnoDB: Database physically writes the file full: wait...
2015-09-18 00:07:58 8732 [Note] InnoDB: Setting log file ./ib_logfile101 size to 48 MB
2015-09-18 00:07:58 8732 [Note] InnoDB: Setting log file ./ib_logfile1 size to 48 MB
2015-09-18 00:07:58 8732 [Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0
2015-09-18 00:07:58 8732 [Warning] InnoDB: New log files created, LSN=45781
2015-09-18 00:07:58 8732 [Note] InnoDB: Doublewrite buffer not found: creating new
2015-09-18 00:07:58 8732 [Note] InnoDB: Doublewrite buffer created
2015-09-18 00:07:58 8732 [Note] InnoDB: 128 rollback segment(s) are active.
2015-09-18 00:07:58 8732 [Warning] InnoDB: Creating foreign key constraint system tables.
2015-09-18 00:07:58 8732 [Note] InnoDB: Foreign key constraint system tables created
2015-09-18 00:07:58 8732 [Note] InnoDB: Creating tablespace and datafile system tables.
2015-09-18 00:07:58 8732 [Note] InnoDB: Tablespace and datafile system tables created.
2015-09-18 00:07:58 8732 [Note] InnoDB: Waiting for purge to start
2015-09-18 00:07:58 8732 [Note] InnoDB: 5.6.26 started; log sequence number 0
A random root password has been set. You will find it in '/root/.mysql_secret'.
2015-09-18 00:07:58 8732 [Note] Binlog end
2015-09-18 00:07:58 8732 [Note] InnoDB: FTS optimize thread exiting.
2015-09-18 00:07:58 8732 [Note] InnoDB: Starting shutdown...
2015-09-18 00:08:00 8732 [Note] InnoDB: Shutdown completed; log sequence number 1625977
2015-09-18 00:08:00 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2015-09-18 00:08:00 0 [Note] /usr/sbin/mysqld (mysqld 5.6.26) starting as process 8757 ...
2015-09-18 00:08:00 8757 [Note] InnoDB: Using atomics to ref count buffer pool pages
2015-09-18 00:08:00 8757 [Note] InnoDB: The InnoDB memory heap is disabled
2015-09-18 00:08:00 8757 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2015-09-18 00:08:00 8757 [Note] InnoDB: Memory barrier is not used
2015-09-18 00:08:00 8757 [Note] InnoDB: Compressed tables use zlib 1.2.3
2015-09-18 00:08:00 8757 [Note] InnoDB: Using Linux native AIO
2015-09-18 00:08:00 8757 [Note] InnoDB: Using CPU crc32 instructions
2015-09-18 00:08:00 8757 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2015-09-18 00:08:00 8757 [Note] InnoDB: Completed initialization of buffer pool
2015-09-18 00:08:00 8757 [Note] InnoDB: Highest supported file format is Barracuda.
2015-09-18 00:08:00 8757 [Note] InnoDB: 128 rollback segment(s) are active.
2015-09-18 00:08:00 8757 [Note] InnoDB: Waiting for purge to start
2015-09-18 00:08:00 8757 [Note] InnoDB: 5.6.26 started; log sequence number 1625977
2015-09-18 00:08:00 8757 [Note] Binlog end
2015-09-18 00:08:00 8757 [Note] InnoDB: FTS optimize thread exiting.
2015-09-18 00:08:00 8757 [Note] InnoDB: Starting shutdown...
2015-09-18 00:08:02 8757 [Note] InnoDB: Shutdown completed; log sequence number 1625987
A RANDOM PASSWORD HAS BEEN SET FOR THE MySQL root USER !
You will find that password in '/root/.mysql_secret'.
You must change that password on your first connect,
no other statement but 'SET PASSWORD' will be accepted.
See the manual for the semantics of the 'password expired' flag.
Also, the account for the anonymous user has been removed.
In addition, you can run:
/usr/bin/mysql_secure_installation
which will also give you the option of removing the test database.
This is strongly recommended for production servers.
See the manual for more instructions.
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/my.cnf and
will be used by default by the server when you start it.
You may edit this file to change server settings
[root@Slave1 mysql]#
9.再次检查是否有用户和组:
[root@Slave1 mysql]# id mysql
uid=496(mysql) gid=493(mysql) groups=493(mysql)
[root@Slave1 mysql]# nl /etc/group | grep mysql
56 mysql:x:493:
[root@Slave1 mysql]# cat /etc/group | grep mysql
mysql:x:493:
[root@Slave1 mysql]# cat /etc/shadow | grep mysql
mysql:!!:16696::::::
[root@Slave1 mysql]#
10. RPM安装方式的文件分布介绍:
Table 2.4 MySQL Installation Layout for Linux RPM Packages
Directory |
Contents of Directory |
/usr/bin |
Client programs and scripts |
/usr/sbin |
The mysqld server |
/var/lib/mysql |
Log files, databases |
/usr/share/info |
MySQL manual in Info format |
/usr/share/man |
Unix man pages |
/usr/include/mysql |
Include (header) files |
/usr/lib/mysql |
Libraries |
/usr/share/mysql |
Miscellaneous support files, including error messages, character set files, sample configuration files, SQL for database installation |
/usr/share/sql-bench |
Benchmarks |
资料来自:http://dev.mysql.com/doc/refman/5.0/en/installation-layouts.html
11.启动:
[root@Slave1 mysql]# service mysql status
ERROR! MySQL is not running
[root@Slave1 mysql]# service mysql start
Starting MySQL...... SUCCESS!
[root@Slave1 mysql]#
先检查mysql的状态,发现未启动,然后启动
[root@Slave1 mysql]# service mysqld start
mysqld: unrecognized service
[root@Slave1 mysql]#
使用上一个安装方法进行尝试,这一次失败
注意mysql和mysqld的不同
12.重新启动并检查
[root@Slave1 mysql]# service mysql start
Starting MySQL.. SUCCESS!
[root@Slave1 mysql]# netstat -anpl | grep mysql
tcp 0 0 :::3306 :::* LISTEN 9269/mysqld
unix 2 [ ACC ] STREAM LISTENING 146938 9269/mysqld /var/lib/mysql/mysql.sock
[root@Slave1 mysql]#
13.安装客户端
[root@Slave1 mysql]# rpm -ivh MySQL-client-5.6.26-1.linux_glibc2.5.x86_64.rpm
warning: MySQL-client-5.6.26-1.linux_glibc2.5.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ########################################### [100%]
1:MySQL-client ########################################### [100%]
[root@Slave1 mysql]#
14.连接到MySQL进行修改
[root@Slave1 mysql]# /etc/init.d/mysql stop
Shutting down MySQL.. SUCCESS!
[root@Slave1 mysql]# mysql_safe --user=mysql --skip-grant-tables --skip-networking &
[1] 9382
[root@Slave1 mysql]# bash: mysql_safe: command not found
^C
[1]+ Exit 127 mysql_safe --user=mysql --skip-grant-tables --skip-networking
[root@Slave1 mysql]# mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
[1] 9384
[root@Slave1 mysql]# 150918 00:46:09 mysqld_safe Logging to '/var/lib/mysql/Slave1.err'.
150918 00:46:09 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
mysql -u root mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.26 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> UPDATE user SET Password=PASSWORD('root') where USER='root';
Query OK, 4 rows affected (0.08 sec)
Rows matched: 4 Changed: 4 Warnings: 0
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.02 sec)
mysql> quit
Bye
[root@Slave1 mysql]# /etc/init.d/mysql restart
Shutting down MySQL..150918 00:47:05 mysqld_safe mysqld from pid file /var/lib/mysql/Slave1.pid ended
SUCCESS!
Starting MySQL. SUCCESS!
[1]+ Done mysqld_safe --user=mysql --skip-grant-tables --skip-networking
[root@Slave1 mysql]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.26
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> exit
Bye
[root@Slave1 mysql]#
与文章:
MySQL学习2_CentOS下安装MySQL遇到问题:Access denied for user 'root'@'localhost'
进行比较
注意mysqld和mysql的区别(来自参考文档):
4.3.1. mysqld — The MySQL Server
mysqld, also known as MySQL Server, is the main program that does most of the work in a MySQL installation. MySQL Server manages access to the MySQL data directory that contains databases and tables. The data directory is also the default location for other information such as log files and status files.
When MySQL server starts, it listens for network connections from client programs and manages access to databases on behalf of those clients.
The mysqld program has many options that can be specified at startup. For a complete list of options, run this command:
shell> mysqld --verbose --help
MySQL Server also has a set of system variables that affect its operation as it runs. System variables can be set at server startup, and many of them can be changed at runtime to effect dynamic server reconfiguration. MySQL Server also has a set of status variables that provide information about its operation. You can monitor these status variables to access runtime performance characteristics.
For a full description of MySQL Server command options, system variables, and status variables, see Section 5.1, “The MySQL Server”. For information about installing MySQL and setting up the initial configuration, see Chapter 2, Installing and Upgrading MySQL.
4.5.1. mysql — The MySQL Command-Line Tool
mysql is a simple SQL shell (with GNU readline capabilities). It supports interactive and noninteractive use. When used interactively, query results are presented in an ASCII-table format. When used noninteractively (for example, as a filter), the result is presented in tab-separated format. The output format can be changed using command options.
If you have problems due to insufficient memory for large result sets, use the --quick option. This forces mysql to retrieve results from the server a row at a time rather than retrieving the entire result set and buffering it in memory before displaying it. This is done by returning the result set using the mysql_use_result() C API function in the client/server library rather than mysql_store_result().
Using mysql is very easy. Invoke it from the prompt of your command interpreter as follows:
shell> mysql db_name
Or:
shell> mysql --user=user_name --password=your_password db_name
Then type an SQL statement, end it with “;”, \g, or \G and press Enter.
Typing Control-C causes mysql to attempt to kill the current statement. If this cannot be done, or Control-C is typed again before the statement is killed, mysql exits. Previously, Control-C caused mysql to exit in all cases.
You can execute SQL statements in a script file (batch file) like this:
shell> mysql db_name < script.sql > output.tab
4.5.1.1. mysql Options
Table 4.2. mysql Options
解释一下就是:
mysql - it's a commandline (administration) tool
命令行工具
mysqld - it's a server daemon. this is the database server main binary (executable)
启动MYSQL服务
mysqld 是服务端程序
mysql是命令行客户端程序
可以参考这两篇文章:
http://segmentfault.com/q/1010000002566029
http://bbs.csdn.net/topics/360046725
15.检查错误:
[root@Slave1 ~]# service mysqld start
mysqld: unrecognized service
[root@Slave1 ~]# rpm -qi mysql-server
package mysql-server is not installed
[root@Slave1 ~]# mysql -version
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
[root@Slave1 ~]#
[root@Slave1 ~]# cd /usr/local/mysql/
[root@Slave1 mysql]# rpm -ivh MySQL-*.rpm
warning: MySQL-client-5.6.26-1.linux_glibc2.5.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ########################################### [100%]
package MySQL-client-5.6.26-1.linux_glibc2.5.x86_64 is already installed
package MySQL-server-5.6.26-1.linux_glibc2.5.x86_64 is already installed
[root@Slave1 mysql]#
[root@Slave1 mysql]# cd /usr/local/mysql/
[root@Slave1 mysql]# service mysqld start
mysqld: unrecognized service
[root@Slave1 mysql]# service mysql start
Starting MySQL SUCCESS!
[root@Slave1 mysql]#
这个错误存疑!