技术开发 频道

MySQL安装记

  网上有很多介绍mysql安装的文档,不过总感觉说得不够详细彻底,今天又有机会安装mysql了,现将步骤记之,希望对mysql初学者有所帮忙 (hehe,其实我就是一个地道的初学者)

  一.环境

  [root@TEST run]# cat /etc/redhat-release

  Red Hat Enterprise Linux AS release 3 (Taroon Update 8)

  [root@TEST run]# uname -a

  Linux TEST 2.4.21-47.ELsmp #1 SMP Wed Jul 5 20:38:41 EDT 2006 i686 i686 i386 GNU/Linux

  mysql版本是 5.0.26-standard

  二.安装

  1.创建mysql用户和mysql组

  [root@TEST home]# groupadd mysql

  [root@TEST home]# useradd -g mysql mysql

  2.将mysql安装包解压到指定目录

  [root@TEST home]# tar -zxvf mysql-standard-5.0.26-linux-i686.tar.gz -C /usr/local/

  3.如果以前没有安装过mysql,就必须创建mysql授权表

  [root@TEST home]# cd /usr/local/

  [root@TEST local]# cd mysql

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

  4.修改文件属组及拥有者权限

  [root@TEST mysql]# pwd

  /usr/local/mysql

  [root@TEST mysql]# ll

  total 92

  drwxr-xr-x 2 503 users 4096 Oct 5 2006 bin

  -rwxr-xr-x 1 503 users 801 Oct 5 2006 configure

  -rw-r--r-- 1 503 users 19071 Oct 4 2006 COPYING

  drwxr-x--- 4 503 users 4096 Oct 5 2006 data

  drwxr-xr-x 2 503 users 4096 Oct 5 2006 docs

  -rw-r--r-- 1 503 users 5806 Oct 5 2006 EXCEPTIONS-CLIENT

  drwxr-xr-x 2 503 users 4096 Oct 5 2006 include

  -rw-r--r-- 1 503 users 7752 Oct 5 2006 INSTALL-BINARY

  drwxr-xr-x 2 503 users 4096 Oct 5 2006 lib

  drwxr-xr-x 4 503 users 4096 Oct 5 2006 man

  drwxr-xr-x 7 503 users 4096 Oct 5 2006 mysql-test

  -rw-r--r-- 1 503 users 1380 Oct 4 2006 README

  drwxr-xr-x 2 503 users 4096 Oct 5 2006 scripts

  drwxr-xr-x 3 503 users 4096 Oct 5 2006 share

  drwxr-xr-x 5 503 users 4096 Oct 5 2006 sql-bench

  drwxr-xr-x 2 503 users 4096 Oct 5 2006 support-files

  drwxr-xr-x 2 503 users 4096 Oct 5 2006 tests

  [root@TEST mysql]# chown -R root . -------把当前目录下所有文件的拥有者修改为root

  [root@TEST mysql]# ll

  total 92

  drwxr-xr-x 2 root users 4096 Oct 5 2006 bin

  -rwxr-xr-x 1 root users 801 Oct 5 2006 configure

  -rw-r--r-- 1 root users 19071 Oct 4 2006 COPYING

  drwxr-x--- 4 root users 4096 Oct 5 2006 data

  drwxr-xr-x 2 root users 4096 Oct 5 2006 docs

  -rw-r--r-- 1 root users 5806 Oct 5 2006 EXCEPTIONS-CLIENT

  drwxr-xr-x 2 root users 4096 Oct 5 2006 include

  -rw-r--r-- 1 root users 7752 Oct 5 2006 INSTALL-BINARY

  drwxr-xr-x 2 root users 4096 Oct 5 2006 lib

  drwxr-xr-x 4 root users 4096 Oct 5 2006 man

  drwxr-xr-x 7 root users 4096 Oct 5 2006 mysql-test

  -rw-r--r-- 1 root users 1380 Oct 4 2006 README

  drwxr-xr-x 2 root users 4096 Oct 5 2006 scripts

  drwxr-xr-x 3 root users 4096 Oct 5 2006 share

  drwxr-xr-x 5 root users 4096 Oct 5 2006 sql-bench

  drwxr-xr-x 2 root users 4096 Oct 5 2006 support-files

  drwxr-xr-x 2 root users 4096 Oct 5 2006 tests

  [root@TEST mysql]# chown -R mysql data ---------- 把data目录拥有者修改为mysql

  [root@TEST mysql]# ll

  total 92

  drwxr-xr-x 2 root users 4096 Oct 5 2006 bin

  -rwxr-xr-x 1 root users 801 Oct 5 2006 configure

  -rw-r--r-- 1 root users 19071 Oct 4 2006 COPYING

  drwxr-x--- 4 mysql users 4096 Oct 5 2006 data

  drwxr-xr-x 2 root users 4096 Oct 5 2006 docs

  -rw-r--r-- 1 root users 5806 Oct 5 2006 EXCEPTIONS-CLIENT

  drwxr-xr-x 2 root users 4096 Oct 5 2006 include

  -rw-r--r-- 1 root users 7752 Oct 5 2006 INSTALL-BINARY

  drwxr-xr-x 2 root users 4096 Oct 5 2006 lib

  drwxr-xr-x 4 root users 4096 Oct 5 2006 man

  drwxr-xr-x 7 root users 4096 Oct 5 2006 mysql-test

  -rw-r--r-- 1 root users 1380 Oct 4 2006 README

  drwxr-xr-x 2 root users 4096 Oct 5 2006 scripts

  drwxr-xr-x 3 root users 4096 Oct 5 2006 share

  drwxr-xr-x 5 root users 4096 Oct 5 2006 sql-bench

  drwxr-xr-x 2 root users 4096 Oct 5 2006 support-files

  drwxr-xr-x 2 root users 4096 Oct 5 2006 tests

  [root@TEST mysql]# chgrp -R mysql . ----------把当前目当下所有文件的属组修改为mysql

  [root@TEST mysql]# ll

  total 92

  drwxr-xr-x 2 root mysql 4096 Oct 5 2006 bin

  -rwxr-xr-x 1 root mysql 801 Oct 5 2006 configure

  -rw-r--r-- 1 root mysql 19071 Oct 4 2006 COPYING

  drwxr-x--- 4 mysql mysql 4096 Oct 5 2006 data

  drwxr-xr-x 2 root mysql 4096 Oct 5 2006 docs

  -rw-r--r-- 1 root mysql 5806 Oct 5 2006 EXCEPTIONS-CLIENT

  drwxr-xr-x 2 root mysql 4096 Oct 5 2006 include

  -rw-r--r-- 1 root mysql 7752 Oct 5 2006 INSTALL-BINARY

  drwxr-xr-x 2 root mysql 4096 Oct 5 2006 lib

  drwxr-xr-x 4 root mysql 4096 Oct 5 2006 man

  drwxr-xr-x 7 root mysql 4096 Oct 5 2006 mysql-test

  -rw-r--r-- 1 root mysql 1380 Oct 4 2006 README

  drwxr-xr-x 2 root mysql 4096 Oct 5 2006 scripts

  drwxr-xr-x 3 root mysql 4096 Oct 5 2006 share

  drwxr-xr-x 5 root mysql 4096 Oct 5 2006 sql-bench

  drwxr-xr-x 2 root mysql 4096 Oct 5 2006 support-files

  drwxr-xr-x 2 root mysql 4096 Oct 5 2006 tests

  5.启动mysql(可惜出错了-_-)

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

  [1] 11222

  [root@TEST mysql]# Starting mysqld daemon with databases from /var/lib/mysql

  STOPPING server from pid file /var/run/mysqld/mysqld.pid

  080410 15:08:06 mysqld ended

  [1]+ Done bin/mysqld_safe --user=mysql

  三.解决安装错误

  1.根据提示找到日志

  [root@TEST mysql]# pwd

  /var/lib/mysql

  [root@TEST mysql]# ls

  ibdata1 ib_logfile0 ib_logfile1 mysql mysql.sock TEST.err test

  [root@TEST mysql]# cat TEST.err

  080410 15:18:23 mysqld started

  080410 15:18:23 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...

  080410 15:18:23 InnoDB: Starting log scan based on checkpoint at

  InnoDB: log sequence number 0 36808.

  InnoDB: Doing recovery: scanned up to log sequence number 0 43655

  080410 15:18:23 InnoDB: Starting an apply batch of log records to the database...

  InnoDB: Progress in percents: 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99

  InnoDB: Apply batch completed

  080410 15:18:24 InnoDB: Started; log sequence number 0 43655

  080410 15:18:24 [ERROR] /usr/local/mysql/bin/mysqld: Can't create/write to file '/var/run/mysqld/mysqld.pid' (Errcode: 2)

  080410 15:18:24 [ERROR] Can't start server: can't create PID file: No such file or directory

  080410 15:18:24 mysqld ended

  据此推断,可能是mysql 启动时会向此文件夹内写一些东西,但 mysql 的进程用户mysql 却没有权限写,导致mysql 无法启动,用touch /var/run/mysqld/mysqld.pid 命令创建mysql 所需要文件,chown -R mysql:mysql/var/run/mysqld将/var/run/mysqld 的目录权限转给 mysql.

  2.解雇方法

  [root@TEST mysql]# cd /var/run/

  [root@TEST run]# mkdir mysqld

  [root@TEST run]# touch mysqld/mysqld.pid

  [root@TEST run]# chown -R mysql:mysql /var/run/mysqld

  3.再尝试启动mysql

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

  [1] 11723

  [root@TEST mysql]# Starting mysqld daemon with databases from /var/lib/mysql

  4.测试mysql

  [root@TEST mysql]# mysql -uroot -p

  Enter password:

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

  Your MySQL connection id is 1 to server version: 5.0.26-standard

  Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

  mysql> show databases;

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

  | Database |

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

  | information_schema |

  | mysql |

  | test |

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

  3 rows in set (0.03 sec)

  到此安装成功

0
相关文章