日期:2014-05-16  浏览次数:20834 次

利用 mysql-5.5.27.tar.gz 来从源码安装 mysql-5.5.27

注意:颜色标注的地方

#! /bin/sh

mkdir -p /var/lib/mysql
mkdir -p /var/lib/data/mysql # 这里创建了mysql的数据目录

cd /var/lib && tar -zvxf mysql-5.5.27.tar.gz && cd mysql-5.5.27
# rm CMakeCache.txt
cmake . -DCMAKE_INSTALL_PREFIX=/var/lib/mysql  -DMYSQL_DATADIR=/var/lib/data/mysql  -DINSTALL_SBINDIR=sbin  -DSYSCONFDIR=/etc  -DINSTALL_PLUGINDIR=lib64/mysql/plugin  -DINSTALL_MANDIR=share/man  -DINSTALL_SHAREDIR=share  -DINSTALL_LIBDIR=lib64/mysql  -DINSTALL_INCLUDEDIR=include/mysql  -DINSTALL_INFODIR=share/info  -DWITH_INNOBASE_STORAGE_ENGINE=1  -DWITH_MYISAM_STORAGE_ENGINE=1   -DWITH_READLINE=1 -DWITH_SSL=system  -DWITH_ZLIB=system  -DWITH_LIBWRAP=0   -DMYSQL_TCP_PORT=3306  -DMYSQL_UNIX_ADDR=/var/lib/data/mysql/mysql.sock  -DENABLED_LOCAL_INFILE=1  -DEXTRA_CHARSETS=all  -DDEFAULT_CHARSET=utf8  -DDEFAULT_COLLATION=utf8_general_ci  -DWITH_EMBEDDED_SERVER=1  -DWITH_DEBUG=0    
make && make install
cd - && cd mysql
cp support-files/my-medium.cnf /etc
cd /etc && mv my-medium.cnf my.cnf && cd /var/lib/mysql-5.5.27
# mysql_install_db 文件无可执行权限
chmod a+rwx ./scripts/mysql_install_db

./scripts/mysql_install_db --user=mysql --basedir=/var/lib/mysql --datadir=/var/lib/data/mysql --defaults-file=/etc/my.cnf # 通过参数 --datadir=/var/lib/data/mysql 来初始化数据库是不能够成功启动数据库的

# 错误:/var/lib/mysql/sbin/mysqld: File './mysql-bin.index' not found 目录权限不够
chown -R mysql:mysql /var/lib/mysql
/var/lib/mysql/bin/mysqld_safe & # 不能成功启动mysql服务

# 错误日志:

121212 19:20:26 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql/data
/var/lib/mysql/sbin/mysqld: Table 'mysql.plugin' doesn't exist
121212 19:20:26 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.
121212 19:20:26 InnoDB: The InnoDB memory heap is disabled
121212 19:20:26 InnoDB: Mutexes and rw_locks use InnoDB's own implementation
121212 19:20:26 InnoDB: Compressed tables use zlib 1.2.3
121212 19:20:26 InnoDB: Initializing buffer pool, size = 128.0M
121212 19:20:26 InnoDB: Completed initialization of buffer pool
121212 19:20:26 InnoDB: highest supported file format is Barracuda.
121212 19:20:26  InnoDB: Waiting for the background threads to start
121212 19:20:27 InnoDB: 1.1.8 started; log sequence number 1595675
121212 19:20:27 [Note] Recovering after a crash using mysql-bin
121212 19:20:27 [Note] Starting crash recovery...
121212 19:20:27 [Note] Crash recovery finished.
121212 19:20:27 [Note] Server hostname (bind-address): '0.0.0.0'; port: 3306
121212 19:20:27 [Note]   - '0.0.0.0' resolves to '0.0.0.0';
121212 19:20:27 [Note] Server socket created on IP: '0.0.0.0'.
121212 19:20:27 [ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.host' doesn't exist
121212 19:20:27 mysqld_safe mysqld from pid file /var/lib/mysql/data/localhost.localdomain.pid ended