welcome to the mysql_mysql安装过程中的一些理解

安装MySQL主要有两种方法:

第一种是通过源码自行编译安装,这种适合高级用户定制MySQL的特性,这里不做说明;

第二种是通过编译过的二进制文件进行安装。

二进制文件安装的方法又分为两种:

(1)是不针对特定平台的通用安装方法,使用的二进制文件是后缀为.tar.gz的压缩文件;

(2)是使用RPM或其他包进行安装,这种安装进程会自动完成系统的相关配置,所以比较方便。

我这里用到的是二进制后缀为.tar.gz的压缩文件

安装文件下载:

wget http://downloads.mysql.com/archives/get/file/mysql-5.5.10-linux2.6-x86_64.tar.gz

解压

[clouder@test ~]$ tar -xvzf mysql-5.5.10-linux2.6-x86_64.tar.gz

[clouder@test ~]$ ls

mysql-5.5.10-linux2.6-x86_64  mysql-5.5.10-linux2.6-x86_64.tar.gz

由于解压后名字太长,索性直接重命名为mysql

[clouder@test ~]$ mv mysql-5.5.10-linux2.6-x86_64 mysql

[clouder@test ~]$ ls

mysql  mysql-5.5.10-linux2.6-x86_64.tar.gz

[clouder@test ~]$

直接初始化

[clouder@test ~]$ cd mysql

[clouder@test mysql]$ ls

bin  COPYING  data  docs  include  INSTALL-BINARY  lib  man  mysql-test  README  scripts  share  sql-bench  support-files

[clouder@test mysql]$ cd scripts/

[clouder@test scripts]$ ls

mysql_install_db

[clouder@test scripts]$ ./mysql_install_db

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.

[clouder@test scripts]$

从上面报错可以看出需要使用一些参数如--basedir或者到解压目录顶部去执行该命令

估计是去执行这个脚本时找不到初始化数据库需要的文件的问题

尝试到解压目录顶部去执行该命令

[clouder@test mysql]$ ./scripts/mysql_install_db

mkdir: ?—??3??????o??????"/var/lib/mysql": ???é??????¤?

chmod: ?—??3?è??é—?"/var/lib/mysql": ?2???‰é?£??a?–??????–??????

chown: ?—????????”¨??·: "mysql"

Cannot change ownership of the database directories to the 'mysql'

user.  Check that you have the necessary permissions and try again.

大概意思是说没权限

百度了下mysql的正规安装,都是要./configue make install 创建mysql用户的

而我这里没这个需求,我只是要简单的在当前用户下把数据库启动

那么尝试加参数

[clouder@test scripts]$ ./mysql_install_db --defaults-file=/home/clouder/mysql/support-files/my-small.cnf --basedir=/home/clouder/mysql --datadir=/home/clouder/mysql/data/tangwb

Installing MySQL system tables...

OK

Filling help tables...

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:

/home/clouder/mysql/bin/mysqladmin -u root password 'new-password'

/home/clouder/mysql/bin/mysqladmin -u root -h test password 'new-password'

Alternatively you can run:

/home/clouder/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 /home/clouder/mysql ; /home/clouder/mysql/bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl

cd /home/clouder/mysql/mysql-test ; perl mysql-test-run.pl

Please report any problems with the /home/clouder/mysql/scripts/mysqlbug script!

[clouder@test scripts]$

--defaults-file=/home/clouder/mysql/support-files/my-small.cnf

我理解的是初始化数据库会去里面找一些参数,根据这些参数来初始化数据库,比如说设定缓存参数啥的,这个会和数据库的性能相关

--basedir=/home/clouder/mysql

数据库的基本目录,也就是初始化数据库所需要的一切脚本啊文件啊都从这个目录获取

--datadir=/home/clouder/mysql/data/tangwb

初始化的数据库的数据目录,可以理解为你数据库的家目录

上面初始化数据库已经完成,我们可以发现data目录下有了一些初始化数据库生成的文件

[clouder@test data]$ pwd

/home/clouder/mysql/data

[clouder@test data]$ ls

mysql  tangwb  test

[clouder@test data]$ cd tangwb

[clouder@test tangwb]$ ls

mysql  performance_schema  test

[clouder@test tangwb]$

[clouder@test tangwb]$ ls

mysql  performance_schema  test

这三个目录其实就对应你数据库里默认创建的3个库 mysql  performance_schema  test

好吧,现在我们尝试启动数据库

[clouder@test mysql]$ /home/clouder/mysql/bin/mysqld --defaults-file=/home/clouder/mysql/support-files/my-small.cnf &

[1] 10081

[clouder@test mysql]$ 151223 16:34:17 [ERROR] Can't find messagefile '/usr/local/mysql/share/errmsg.sys'

151223 16:34:17 [Warning] Can't create test file /usr/local/mysql/data/test.lower-test

151223 16:34:17 [Warning] Can't create test file /usr/local/mysql/data/test.lower-test

/home/clouder/mysql/bin/mysqld: Can't change dir to '/usr/local/mysql/data/' (Errcode: 2)

151223 16:34:17 [ERROR] Aborting

151223 16:34:17 [Note]

[1]+  Exit 1                  /home/clouder/mysql/bin/mysqld --defaults-file=/home/clouder/mysql/support-files/my-small.cnf

[clouder@test mysql]$

因为我们不是正规创建的数据库,以这个配置文件去启动数据库的时候,它是按默认配置去起数据库的

这自然导致一些文件是找不到的

所以得改配置文件,指定数据库的basedir和datadir

在配置文件my-small.cnf加入

basedir=/home/clouder/mysql

datadir=/home/clouder/mysql/data/wubai

修改port为14000(这个不是必要的,只是我想试试改下默认的3306端口)

最后大致是这个样子

...

[mysqld]

port            = 14000

socket          = /tmp/mysql.sock

skip-external-locking

key_buffer_size = 16K

max_allowed_packet = 1M

table_open_cache = 4

sort_buffer_size = 64K

read_buffer_size = 256K

read_rnd_buffer_size = 256K

net_buffer_length = 2K

thread_stack = 128K

basedir=/home/clouder/mysql

datadir=/home/clouder/mysql/data/tangwb

...

再次尝试启动数据库,启动成功

[clouder@test mysql]$ /home/clouder/mysql/bin/mysqld --defaults-file=/tmp/my-small.cnf &

[1] 10204

[clouder@test mysql]$ 151223 16:41:18 [Note] Plugin 'FEDERATED' is disabled.

151223 16:41:18 InnoDB: The InnoDB memory heap is disabled

151223 16:41:18 InnoDB: Mutexes and rw_locks use GCC atomic builtins

151223 16:41:18 InnoDB: Compressed tables use zlib 1.2.3

151223 16:41:18 InnoDB: Using Linux native AIO

151223 16:41:18 InnoDB: Initializing buffer pool, size = 128.0M

151223 16:41:18 InnoDB: Completed initialization of buffer pool

InnoDB: The first specified data file ./ibdata1 did not exist:

InnoDB: a new database to be created!

151223 16:41:18  InnoDB: Setting file ./ibdata1 size to 10 MB

InnoDB: Database physically writes the file full: wait...

151223 16:41:19  InnoDB: Log file ./ib_logfile0 did not exist: new to be created

InnoDB: Setting log file ./ib_logfile0 size to 5 MB

InnoDB: Database physically writes the file full: wait...

151223 16:41:19  InnoDB: Log file ./ib_logfile1 did not exist: new to be created

InnoDB: Setting log file ./ib_logfile1 size to 5 MB

InnoDB: Database physically writes the file full: wait...

InnoDB: Doublewrite buffer not found: creating new

InnoDB: Doublewrite buffer created

InnoDB: 127 rollback segment(s) active.

InnoDB: Creating foreign key constraint system tables

InnoDB: Foreign key constraint system tables created

151223 16:41:19  InnoDB: Waiting for the background threads to start

151223 16:41:20 InnoDB: 1.1.5 started; log sequence number 0

151223 16:41:20 [Note] Event Scheduler: Loaded 0 events

151223 16:41:20 [Note] /home/clouder/mysql/bin/mysqld: ready for connections.

Version: '5.5.10'  socket: '/tmp/mysql.sock'  port: 14000  MySQL Community Server (GPL)

[clouder@test mysql]$

[clouder@test mysql]$ netstat -lpnt

(Not all processes could be identified, non-owned process info

will not be shown, you would have to be root to see it all.)

Active Internet connections (only servers)

Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name

tcp        0      0 0.0.0.0:111                 0.0.0.0:*                   LISTEN      -

tcp        0      0 0.0.0.0:14000               0.0.0.0:*                   LISTEN      10204/mysqld

tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      -

tcp        0      0 127.0.0.1:631               0.0.0.0:*                   LISTEN      -

tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN      -

tcp        0      0 0.0.0.0:48378               0.0.0.0:*                   LISTEN      -

tcp        0      0 :::111                      :::*                        LISTEN      -

tcp        0      0 :::60372                    :::*                        LISTEN      -

tcp        0      0 :::22                       :::*                        LISTEN      -

tcp        0      0 ::1:631                     :::*                        LISTEN      -

tcp        0      0 ::1:25                      :::*                        LISTEN      -

[clouder@test mysql]$ ps -ef |grep mysql

clouder  10204  9994  1 16:41 pts/1    00:00:00 /home/clouder/mysql/bin/mysqld --defaults-file=/tmp/my-small.cnf

clouder  10224  9994  0 16:41 pts/1    00:00:00 grep mysql

[clouder@test mysql]$

登录数据库看看吧

[clouder@test mysql]$ /home/clouder/mysql/bin/mysql -uroot -P14000

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

Your MySQL connection id is 1

Server version: 5.5.10 MySQL Community Server (GPL)

Copyright (c) 2000, 2010, 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.00 sec)

mysql>

刚才我们是在/home/clouder/mysql/data/tangwb目录下有三个目录的,对应我们默认的3个数据库

因为test数据库是没有东西的,所以test目录为空

[clouder@test test]$ pwd

/home/clouder/mysql/data/tangwb/test

[clouder@test test]$ ls

[clouder@test test]$

我们在test数据库尝试创建表,再观察test目录,可以看到下面就有文件了

mysql> use test

Database changed

mysql> create table blog_user

-> (

->   user_Name char(15) not null check(user_Name !=''),

->   user_Password char(15) not null,

->   user_emial varchar(20) not null unique,

->   primary key(user_Name)

->

-> )engine=innodb default charset=utf8 auto_increment=1;

Query OK, 0 rows affected (0.11 sec)

mysql>

[clouder@test test]$ ls

blog_user.frm

[clouder@test test]$

我们尝试新建一个数据库blog,你会发现/home/clouder/mysql/data/tangwb目录会为其新分配一个目录blog

mysql> create database blog;

Query OK, 1 row affected (0.00 sec)

mysql>

[clouder@test tangwb]$ ls

blog  ibdata1  ib_logfile0  ib_logfile1  mysql  performance_schema  test  test.pid

[clouder@test tangwb]$

好了,刚才我们启动数据库是以14000端口启动的,现在我们尝试以14001端口启动

首先停掉数据库

[clouder@test mysql]$ netstat -lpnt

(Not all processes could be identified, non-owned process info

will not be shown, you would have to be root to see it all.)

Active Internet connections (only servers)

Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name

tcp        0      0 0.0.0.0:111                 0.0.0.0:*                   LISTEN      -

tcp        0      0 0.0.0.0:14000               0.0.0.0:*                   LISTEN      10204/mysqld

tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      -

tcp        0      0 127.0.0.1:631               0.0.0.0:*                   LISTEN      -

tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN      -

tcp        0      0 0.0.0.0:48378               0.0.0.0:*                   LISTEN      -

tcp        0      0 :::111                      :::*                        LISTEN      -

tcp        0      0 :::60372                    :::*                        LISTEN      -

tcp        0      0 :::22                       :::*                        LISTEN      -

tcp        0      0 ::1:631                     :::*                        LISTEN      -

tcp        0      0 ::1:25                      :::*                        LISTEN      -

[clouder@test mysql]$ kill -9 10204

[clouder@test mysql]$ ps -ef |grep mysql

clouder  10427  9994  0 16:53 pts/1    00:00:00 grep mysql

[clouder@test mysql]$

然后修改配置文件把14000改成14001并再次启动数据库

[clouder@test mysql]$ sed -i 's/14000/14001/' /tmp/my-small.cnf

[clouder@test mysql]$ /home/clouder/mysql/bin/mysqld --defaults-file=/tmp/my-small.cnf &

[1] 10460

[clouder@test mysql]$ 151223 16:55:32 [Note] Plugin 'FEDERATED' is disabled.

151223 16:55:32 InnoDB: The InnoDB memory heap is disabled

151223 16:55:32 InnoDB: Mutexes and rw_locks use GCC atomic builtins

151223 16:55:32 InnoDB: Compressed tables use zlib 1.2.3

151223 16:55:32 InnoDB: Using Linux native AIO

151223 16:55:32 InnoDB: Initializing buffer pool, size = 128.0M

151223 16:55:32 InnoDB: Completed initialization of buffer pool

151223 16:55:32 InnoDB: highest supported file format is Barracuda.

InnoDB: The log sequence number in ibdata files does not match

InnoDB: the log sequence number in the ib_logfiles!

151223 16:55:32  InnoDB: Database was not shut down normally!

InnoDB: Starting crash recovery.

InnoDB: Reading tablespace information from the .ibd files...

InnoDB: Restoring possible half-written data pages from the doublewrite

InnoDB: buffer...

151223 16:55:32  InnoDB: Waiting for the background threads to start

151223 16:55:33 InnoDB: 1.1.5 started; log sequence number 1599774

151223 16:55:33 [Note] Event Scheduler: Loaded 0 events

151223 16:55:33 [Note] /home/clouder/mysql/bin/mysqld: ready for connections.

Version: '5.5.10'  socket: '/tmp/mysql.sock'  port: 14001  MySQL Community Server (GPL)

[clouder@test mysql]$

[clouder@test mysql]$ netstat -lpnt

(Not all processes could be identified, non-owned process info

will not be shown, you would have to be root to see it all.)

Active Internet connections (only servers)

Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name

tcp        0      0 0.0.0.0:111                 0.0.0.0:*                   LISTEN      -

tcp        0      0 0.0.0.0:14001               0.0.0.0:*                   LISTEN      10460/mysqld

tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      -

tcp        0      0 127.0.0.1:631               0.0.0.0:*                   LISTEN      -

tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN      -

tcp        0      0 0.0.0.0:48378               0.0.0.0:*                   LISTEN      -

tcp        0      0 :::111                      :::*                        LISTEN      -

tcp        0      0 :::60372                    :::*                        LISTEN      -

tcp        0      0 :::22                       :::*                        LISTEN      -

tcp        0      0 ::1:631                     :::*                        LISTEN      -

tcp        0      0 ::1:25                      :::*                        LISTEN      -

[clouder@test mysql]$

[clouder@test mysql]$ ps -ef |grep mysql

clouder  10460  9994  0 16:55 pts/1    00:00:00 /home/clouder/mysql/bin/mysqld --defaults-file=/tmp/my-small.cnf

clouder  10481  9994  0 16:55 pts/1    00:00:00 grep mysql

[clouder@test mysql]$

再次登录数据库

[clouder@test mysql]$ /home/clouder/mysql/bin/mysql -uroot -P14001

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

Your MySQL connection id is 1

Server version: 5.5.10 MySQL Community Server (GPL)

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

| blog               |

| mysql              |

| performance_schema |

| test               |

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

5 rows in set (0.00 sec)

mysql> use test

Reading table information for completion of table and column names

You can turn off this feature to get a quicker startup with -A

Database changed

mysql> show tables;

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

| Tables_in_test |

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

| blog_user      |

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

1 row in set (0.00 sec)

mysql>

看见了没,这个就是你刚才以14000端口启动的数据库,所以端口是和数据库无关的,启动端口只是你进入数据库的一个通道

真正决定你进入哪个数据库是你的datadir

我以前一直以为启动数据库后配置文件还是被占用的,而事实是启动数据库后配置文件就和你的数据库运行没关系了

[clouder@test mysql]$ netstat -lpnt

(Not all processes could be identified, non-owned process info

will not be shown, you would have to be root to see it all.)

Active Internet connections (only servers)

Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name

tcp        0      0 0.0.0.0:111                 0.0.0.0:*                   LISTEN      -

tcp        0      0 0.0.0.0:14001               0.0.0.0:*                   LISTEN      10460/mysqld

tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      -

tcp        0      0 127.0.0.1:631               0.0.0.0:*                   LISTEN      -

tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN      -

tcp        0      0 0.0.0.0:48378               0.0.0.0:*                   LISTEN      -

tcp        0      0 :::111                      :::*                        LISTEN      -

tcp        0      0 :::60372                    :::*                        LISTEN      -

tcp        0      0 :::22                       :::*                        LISTEN      -

tcp        0      0 ::1:631                     :::*                        LISTEN      -

tcp        0      0 ::1:25                      :::*                        LISTEN      -

[clouder@test mysql]$

[clouder@test 10460]$ cd /proc/10460/fd(数据库进程打开的文件中没有配置文件)

[clouder@test fd]$ ll

????”¨é?? 0

lrwx------. 1 clouder clouder 64 12??? 23 16:55 0 -> /dev/pts/1

lrwx------. 1 clouder clouder 64 12??? 23 16:55 1 -> /dev/pts/1

lrwx------. 1 clouder clouder 64 12??? 23 16:55 10 -> socket:[4732570]

lrwx------. 1 clouder clouder 64 12??? 23 16:55 11 -> /tmp/ibaw8OXa (deleted)

lrwx------. 1 clouder clouder 64 12??? 23 16:55 12 -> socket:[4732571]

lrwx------. 1 clouder clouder 64 12??? 23 16:55 13 -> /home/clouder/mysql/data/tangwb/mysql/db.MYI

lrwx------. 1 clouder clouder 64 12??? 23 16:55 14 -> /home/clouder/mysql/data/tangwb/mysql/db.MYD

lrwx------. 1 clouder clouder 64 12??? 23 16:55 15 -> /home/clouder/mysql/data/tangwb/mysql/user.MYI

lrwx------. 1 clouder clouder 64 12??? 23 16:55 16 -> /home/clouder/mysql/data/tangwb/mysql/user.MYD

lrwx------. 1 clouder clouder 64 12??? 23 16:55 17 -> /home/clouder/mysql/data/tangwb/mysql/event.MYI

lrwx------. 1 clouder clouder 64 12??? 23 16:55 18 -> /home/clouder/mysql/data/tangwb/mysql/event.MYD

lrwx------. 1 clouder clouder 64 12??? 23 16:55 2 -> /dev/pts/1

lrwx------. 1 clouder clouder 64 12??? 23 16:55 3 -> /home/clouder/mysql/data/tangwb/ibdata1

lrwx------. 1 clouder clouder 64 12??? 23 16:55 4 -> /tmp/ibEDuHUa (deleted)

lrwx------. 1 clouder clouder 64 12??? 23 16:55 5 -> /tmp/ibYHoXSF (deleted)

lrwx------. 1 clouder clouder 64 12??? 23 16:55 6 -> /tmp/ibc9RdRa (deleted)

lrwx------. 1 clouder clouder 64 12??? 23 16:55 7 -> /tmp/ibm4FhRF (deleted)

lrwx------. 1 clouder clouder 64 12??? 23 16:55 8 -> /home/clouder/mysql/data/tangwb/ib_logfile0

lrwx------. 1 clouder clouder 64 12??? 23 16:55 9 -> /home/clouder/mysql/data/tangwb/ib_logfile1

[clouder@test fd]$

[clouder@test fd]$

[clouder@test fd]$ lsof |grep my-small.cnf(整个系统中配置文件也未被任何进程占用)

[clouder@test fd]$

阅读(1677) | 评论(0) | 转发(0) |

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值