mysql安装z dig_CentOS安装MySQL数据库的三种方法

最近在CentOS 5.10上安装最新版的mysql5.6.21时遇到了麻烦。于是将mysql文档中的关于如何在Linux上安装mysql的部分仔细的读了一遍。总结起来在CentOS或者Red Hat上安装mysql可以有三种方式:

1)使用rpm -ivh ...或者 yum install ... (一般推荐使用rpm来安装)

2)使用编译好的通用二进制版本的mysql来安装(Generic Binaries mysql) (在方法一失败时,可以使用方法2来安装)

3)使用源码来编译安装。

1.在CentOS 5.10上安装最新版的mysql5.6.21时遇到的麻烦

2.Installing MySQL on Unix/Linux Using Generic Binaries(使用通用二进制版本的mysql来安装)

当使用rpm或者yum方法安装失败时,可以使用该方法进行安装。因为通用二进制版本对glibc等lib库的版本要求不是很高。所以使用这种方法,可以很好的解决:在低版本的CentOS上安装高版本的mysql。其安装方法如下。

2.1 下载

打开网页:http://dev.mysql.com/downloads/mysql/

在Select Platform: 中选择 Linux - Generic

然后下载最下面的:mysql-5.6.21-linux-glibc2.5-i686.tar.gz (有64位的和32位的,选择自己需要的)

2.2 安装

具体安装步骤,mysql文档中有详细说明:

To install and user a MySQL binary distribution, the basic command sequence looks like this:

shell> groupadd mysql

shell> useradd -r -g mysql mysql

shell> cd /usr/local

shell> tar zxvf /path/to/mysql-VERSION-OS.tar.gz

shell> ln -s full-path-to-mysql-VERSION-OSmysql

shell> cd mysql

shell> chown -R mysql .

shell> chgrp -R mysql .

shell> scripts/mysql_install_db --user=mysql

shell> chown -R root .

shell> chown -R mysql data

shell> bin/mysqld_safe --user=mysql &

# Next command is optional

shell> cp support-files/mysql.server /etc/init.d/mysql.server

我自己的安装过程如下:

[root@localhost mysql]# groupadd mysql

[root@localhost mysql]# useradd -r -g mysql mysql

[root@localhost mysql]# cd /usr/local

[root@localhost mysql]# tar zxvf /root/mysql-5.6.21-linux-glibc2.5-i686.tar.gz

[root@localhost local]# ll

total 76

drwxr-xr-x  2 root root 4096 Nov  7 05:43 bin

drwxr-xr-x  2 root root 4096 May 11  2011 etc

drwxr-xr-x  2 root root 4096 May 11  2011 games

drwxr-xr-x  3 root root 4096 Nov  7 05:43 include

drwxr-xr-x  4 root root 4096 Nov  7 05:43 lib

drwxr-xr-x  2 root root 4096 May 11  2011 libexec

drwxr-xr-x 13 root root 4096 Nov  7 20:42 mysql-5.6.21-linux-glibc2.5-i686

drwxr-xr-x  2 root root 4096 May 11  2011 sbin

drwxr-xr-x  4 root root 4096 Nov  7 01:15 share

drwxr-xr-x  2 root root 4096 May 11  2011 src

[root@localhost local]# pwd

/usr/local

[root@localhost local]# ln -s /usr/local/mysql-5.6.21-linux-glibc2.5-i686 mysql

[root@localhost local]# cd mysql

[root@localhost mysql]# chown -R mysql .

[root@localhost mysql]# chgrp -R mysql .

[root@localhost mysql]# scripts/mysql_install_db --user=mysql

Installing MySQL system tables...2014-11-07 20:45:37 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explic                    it_defaults_for_timestamp server option (see documentation for more details).

2014-11-07 20:45:37 4083 [Note] InnoDB: Using mutexes to ref count buffer pool pages

2014-11-07 20:45:37 4083 [Note] InnoDB: The InnoDB memory heap is disabled

2014-11-07 20:45:37 4083 [Note] InnoDB: Mutexes and rw_locks use InnoDB's own implementation

2014-11-07 20:45:37 4083 [Note] InnoDB: Memory barrier is not used

2014-11-07 20:45:37 4083 [Note] InnoDB: Compressed tables use zlib 1.2.3

2014-11-07 20:45:37 4083 [Note] InnoDB: Using Linux native AIO

2014-11-07 20:45:37 4083 [Note] InnoDB: Not using CPU crc32 instructions

2014-11-07 20:45:37 4083 [Note] InnoDB: Initializing buffer pool, size = 128.0M

2014-11-07 20:45:37 4083 [Note] InnoDB: Completed initialization of buffer pool

2014-11-07 20:45:37 4083 [Note] InnoDB: The first specified data file ./ibdata1 did not exist: a new database to be created!

2014-11-07 20:45:37 4083 [Note] InnoDB: Setting file ./ibdata1 size to 12 MB

2014-11-07 20:45:37 4083 [Note] InnoDB: Database physically writes the file full: wait...

2014-11-07 20:45:37 4083 [Note] InnoDB: Setting log file ./ib_logfile101 size to 48 MB

2014-11-07 20:45:38 4083 [Note] InnoDB: Setting log file ./ib_logfile1 size to 48 MB

2014-11-07 20:45:38 4083 [Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0

2014-11-07 20:45:38 4083 [Warning] InnoDB: New log files created, LSN=45781

2014-11-07 20:45:38 4083 [Note] InnoDB: Doublewrite buffer not found: creating new

2014-11-07 20:45:38 4083 [Note] InnoDB: Doublewrite buffer created

2014-11-07 20:45:38 4083 [Note] InnoDB: 128 rollback segment(s) are active.

2014-11-07 20:45:38 4083 [Warning] InnoDB: Creating foreign key constraint system tables.

2014-11-07 20:45:39 4083 [Note] InnoDB: Foreign key constraint system tables created

2014-11-07 20:45:39 4083 [Note] InnoDB: Creating tablespace and datafile system tables.

2014-11-07 20:45:39 4083 [Note] InnoDB: Tablespace and datafile system tables created.

2014-11-07 20:45:39 4083 [Note] InnoDB: Waiting for purge to start

2014-11-07 20:45:39 4083 [Note] InnoDB: 5.6.21 started; log sequence number 0

2014-11-07 20:45:39 4083 [Note] Binlog end

2014-11-07 20:45:39 4083 [Note] InnoDB: FTS optimize thread exiting.

2014-11-07 20:45:39 4083 [Note] InnoDB: Starting shutdown...

2014-11-07 20:45:41 4083 [Note] InnoDB: Shutdown completed; log sequence number 1625977

OK

Filling help tables...2014-11-07 20:45:41 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults                    _for_timestamp server option (see documentation for more details).

2014-11-07 20:45:41 4105 [Note] InnoDB: Using mutexes to ref count buffer pool pages

2014-11-07 20:45:41 4105 [Note] InnoDB: The InnoDB memory heap is disabled

2014-11-07 20:45:41 4105 [Note] InnoDB: Mutexes and rw_locks use InnoDB's own implementation

2014-11-07 20:45:41 4105 [Note] InnoDB: Memory barrier is not used

2014-11-07 20:45:41 4105 [Note] InnoDB: Compressed tables use zlib 1.2.3

2014-11-07 20:45:41 4105 [Note] InnoDB: Using Linux native AIO

2014-11-07 20:45:41 4105 [Note] InnoDB: Not using CPU crc32 instructions

2014-11-07 20:45:41 4105 [Note] InnoDB: Initializing buffer pool, size = 128.0M

2014-11-07 20:45:41 4105 [Note] InnoDB: Completed initialization of buffer pool

2014-11-07 20:45:41 4105 [Note] InnoDB: Highest supported file format is Barracuda.

2014-11-07 20:45:41 4105 [Note] InnoDB: 128 rollback segment(s) are active.

2014-11-07 20:45:41 4105 [Note] InnoDB: Waiting for purge to start

2014-11-07 20:45:41 4105 [Note] InnoDB: 5.6.21 started; log sequence number 1625977

2014-11-07 20:45:41 4105 [Note] Binlog end

2014-11-07 20:45:41 4105 [Note] InnoDB: FTS optimize thread exiting.

2014-11-07 20:45:41 4105 [Note] InnoDB: Starting shutdown...

2014-11-07 20:45:43 4105 [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

[root@localhost mysql]# chown -R root .

[root@localhost mysql]# chown -R mysql data

[root@localhost mysql]#bin/mysqld_safe --user=mysql &

[1] 4144

[root@localhost mysql]# 141107 20:52:14 mysqld_safe Logging to '/usr/local/mysql/data/localhost.localdomain.err'.

141107 20:52:14 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data

[root@localhost mysql]# cp support-files/mysql.server /etc/init.d/mysql.server

[root@localhost mysql]# ps -elf | grep mysql

4 S root      4144  3430  0  85   0 -  1149 wait   20:52 pts/0    00:00:00 /bin/sh bin/mysqld_safe --user=mysql

4 S mysql     4234  4144  4  76   0 - 195029 stext 20:52 pts/0    00:00:02 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datad                    data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/usr/local/mysql/data/localhost.localdomain.err --pid-file=/usr/lo                    host.localdomain.pid

0 R root      4262  3430  0  78   0 -  1008 -      20:53 pts/0    00:00:00 grep mysql

[root@localhost mysql]# ./bin/mysqladmin -u root password 'xxxxxx'

Warning: Using a password on the command line interface can be insecure.

[root@localhost mysql]# ./bin/mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL

SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MySQL to secure it, we'll need the current

password for the root user.  If you've just installed MySQL, and

you haven't set the root password yet, the password will be blank,

so you should just press enter here.

Enter current password for root (enter for none):

OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MySQL

root user without the proper authorisation.

You already have a root password set, so you can safely answer 'n'.

Change the root password? [Y/n] n

... skipping.

By default, a MySQL installation has an anonymous user, allowing anyone

to log into MySQL without having to have a user account created for

them.  This is intended only for testing, and to make the installation

go a bit smoother.  You should remove them before moving into a

production environment.

Remove anonymous users? [Y/n] y

... Success!

Normally, root should only be allowed to connect from 'localhost'.  This

ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] y

... Success!

By default, MySQL comes with a database named 'test' that anyone can

access.  This is also intended only for testing, and should be removed

before moving into a production environment.

Remove test database and access to it? [Y/n] y

- Dropping test database...

... Success!

- Removing privileges on test database...

... Success!

Reloading the privilege tables will ensure that all changes made so far

will take effect immediately.

Reload privilege tables now? [Y/n] y

... Success!

All done!  If you've completed all of the above steps, your MySQL

installation should now be secure.

Thanks for using MySQL!

Cleaning up...

修改 /root/.bash_profile中的PATH:

[root@localhost ~]# cat /root/.bash_profile

# .bash_profile

# Get the aliases and functions

if [ -f ~/.bashrc ]; then

. ~/.bashrc

fi

# User specific environment and startup programs

PATH=$PATH:/usr/local/mysql/bin:$HOME/bin

export PATH

unset USERNAME

[root@localhost ~]# pwd

/root

[root@localhost ~]# mysql -uroot -p

Enter password:

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 14

Server version: 5.6.21 MySQL Community Server (GPL)

Copyright (c) 2000, 2014, 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 |

+--------------------+

3 rows in set (0.00 sec)

mysql> user mysql;

mysql> select host,user,password from user;

+-----------+------+-------------------------------------------+

| host      | user | password                                  |

+-----------+------+-------------------------------------------+

| localhost | root | *BDC62F68AF8F0B8BFAE27FF782C5D8CE9F4BAFCB |

| 127.0.0.1 | root |                                           |

| ::1       | root |                                           |

+-----------+------+-------------------------------------------+

3 rows in set (0.01 sec)

mysql> update user set password=password('xxxxxx') where password='';

Query OK, 2 rows affected (0.02 sec)

Rows matched: 2  Changed: 2  Warnings: 0

mysql> select host,user,password from user;

+-----------+------+-------------------------------------------+

| host      | user | password                                  |

+-----------+------+-------------------------------------------+

| localhost | root | *BDC62F68AF8F0B8BFAE27FF782C5D8CE9F4BAFCB |

| 127.0.0.1 | root | *BDC62F68AF8F0B8BFAE27FF782C5D8CE9F4BAFCB |

| ::1       | root | *BDC62F68AF8F0B8BFAE27FF782C5D8CE9F4BAFCB |

+-----------+------+-------------------------------------------+

3 rows in set (0.00 sec)

到这里,第二种安装方法结束。

该安装方法下,启动mysql命令为:mysqld_safe --user=mysql &

关闭mysql命令为:mysqladmin -uroot -p shutdown

3.使用源码安装

略。

阅读(18065) | 评论(0) | 转发(1) |

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值