linux安装mysql-编译安装

常规编译安装:./configure;make;make install

linux系统centos 6.5,mysql版本5.5.54,所需安装包cmake-2.8.8.tar.gz、mysql-5.5.54.tar.gz、ncurses-devel-5.7-4.20090207.el6.x86_64.rpm

 

查看linux系统信息

[root@oldboy ~]# cat /etc/redhat-release 
CentOS release 6.5 (Final)
[root@oldboy ~]# uname -a
Linux oldboy 2.6.32-431.el6.x86_64 #1 SMP Fri Nov 22 03:15:09 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux

 

挂载磁盘并安装gcc-c++

[root@oldboy ~]# mount /dev/cdrom /mnt
mount: block device /dev/sr0 is write-protected, mounting read-only
[root@oldboy ~]# yum -y install gcc-c++

如果没有安装gcc-c++,后面./configure时会报如下错误

---------------------------------------------
Error when bootstrapping CMake:
Cannot find appropriate C++ compiler on this system.
Please specify one using environment variable CXX.
See cmake_bootstrap.log for compilers attempted.
---------------------------------------------
Log of errors: /usr/local/cmake-3.0.2/Bootstrap.cmk/cmake_bootstrap.log

 

创建更新包目录,并将三个安装包上传至该目录下,赋予执行权限

[root@oldboy ~]# mkdir -p /home/oldboy/tools
[root@oldboy ~]# cd /home/oldboy/tools
[root@oldboy tools]# chmod +x *

 

安装ncurses-devel

[root@oldboy tools]# yum -y install ncurses-devel-5.7-4.20090207.el6.x86_64.rpm 
…………………
Complete!

 

安装cmake

[root@oldboy tools]# tar zxf cmake-2.8.8.tar.gz
[root@oldboy tools]# cd cmake-2.8.8
[root@oldboy cmake-2.8.8]# ./configure
…………………
CMake has bootstrapped.  Now run gmake.
[root@oldboy cmake-2.8.8]# gmake
……………………
[100%] Built target foo
[root@oldboy cmake-2.8.8]# gmake install
……………………
-- Installing: /usr/local/doc/cmake-2.8/cpack.docbook
-- Installing: /usr/local/share/aclocal/cmake.m4

 

安装mysql,make&&make install 耗时较长

[root@oldboy tools]# groupadd mysql
[root@oldboy tools]# useradd -M mysql -g mysql -s /sbin/nologin
[root@oldboy tools]# tar zxf mysql-5.5.54.tar.gz 
[root@oldboy tools]# cd mysql-5.5.54
[root@oldboy mysql-5.5.54]# cmake . -DCMAKE_INSTALL_PREFIX=/application/mysql-5.5.54 \
-DMYSQL_DATADIR=/application/mysql-5.5.54/data \
-DMYSQL_UNIX_ADDR=/application/mysql-5.5.54/tmp/mysql.sock \
-DEXTRA_CHARSETS=gbk,gb2312,utf8,ascii \
-DENABLED_LOCAL_INFILE=ON \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_FEDERATED_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 \
-DWITHOUT_PARTITION_STORAGE_ENGINE=1 \
-DWITH_FAST_MUTEXES=1 \
-DWITH_ZLIB=bundled \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_READLINE=1 \
-DWITH_EMBEDDED_SERVER=1 \
-DWITH_DEBUG=0
……………………
-- Configuring done
-- Generating done
-- Build files have been written to: /home/oldboy/tools/mysql-5.5.54
[root@oldboy mysql-5.5.54]# make && make install
……………………
-- Installing: /application/mysql-5.5.54/man/man1/my_print_defaults.1
-- Installing: /application/mysql-5.5.54/man/man8/mysqld.8
[root@oldboy mysql-5.5.54]# ll /application/mysql/data/
总用量 4
drwxr-xr-x. 2 root root 4096 6月 22 00:18 test

 

创建软连接、复制mysql的配置文件到/etc/my.cnf文件,并将mysql的可执行文件bin目录加入PATH环境变量

[root@oldboy mysql-5.5.54]# ln -s /application/mysql-5.5.54/ /application/mysql
[root@oldboy mysql-5.5.54]# cp support-files/my-small.cnf /etc/my.cnf
cp: overwrite `/etc/my.cnf'? y
[root@oldboy mysql-5.5.54]# echo 'export PATH=/application/mysql/bin:$PATH'>>/etc/profile
[root@oldboy mysql-5.5.54]# source /etc/profile
[root@oldboy mysql-5.5.54]# echo $PATH
/application/mysql/bin:/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin

 

修改安装目录的权限,并编译安装,出现两个ok表示此步骤没有问题

[root@oldboy mysql-5.5.54]# chown -R mysql.mysql /application/mysql/data/
[root@oldboy mysql-5.5.54]# chmod -R 1777 /tmp/
[root@oldboy mysql-5.5.54]# cd /application/mysql/scripts/
[root@oldboy scripts]# ./mysql_install_db --basedir=/application/mysql/ --datadir=/application/mysql/data/ --user=mysql
……………………
Installing MySQL system tables...
181126 20:20:08 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
181126 20:20:08 [Note] /application/mysql//bin/mysqld (mysqld 5.5.54) starting as process 48267 ...
OK
Filling help tables...
181126 20:20:08 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
181126 20:20:08 [Note] /application/mysql//bin/mysqld (mysqld 5.5.54) starting as process 48274 ...
OK
……………………
Please report any problems at http://bugs.mysql.com/

 

复制mysql的启动文件到/etc/init.d/下并命名为mysqld

[root@oldboy scripts]# cd /home/oldboy/tools/mysql-5.5.54
[root@oldboy mysql-5.5.54]# cp support-files/mysql.server /etc/init.d/mysqld
[root@oldboy mysql-5.5.54]# chmod +x /etc/init.d/mysqld 
[root@oldboy mysql-5.5.54]# mkdir -p /application/mysql-5.5.54/tmp
[root@oldboy mysql-5.5.54]# chown -R mysql.mysql /application/mysql-5.5.54/tmp

 

启动mysql

[root@oldboy mysql-5.5.54]# /etc/init.d/mysqld start
Starting MySQL.Logging to '/application/mysql-5.5.54/data/oldboy.err'.
.[  OK  ]

 

给root用户设置密码并通过root登录mysql数据库

[root@oldboy mysql-5.5.54]# /application/mysql//bin/mysqladmin -u root password 'oldboy'
[root@oldboy mysql-5.5.54]# mysql -uroot -poldboy
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.5.54 Source distribution

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

 

posted @ 2018-11-26 20:31  Forever77  阅读(385)  评论(0编辑  收藏  举报