MySQL源码编译安装(Aliyun Linux版)

来源:互联网 发布:用ps做淘宝店长图 编辑:程序博客网 时间:2024/06/02 08:49

安装前的准备工作,工具包的安装

# yum -y install gcc libxml2-dev curl screen \libpng12-dev autoconf libpcre3-dev make bzip2 \libevent-dev patch libjpeg62-dev libcurl4-openssl-dev \libfreetype6-dev g++ libtool libncurses5-dev psmisc lrzsz

以下安装中涉及的几点需要提前说明的问题:

1. 所有下载的文件将保存在 /usr/local/software/ 目录下

2. mysql 将以mysql用户运行,而且将加入 service 开机自动运行

3. mysql 将被安装在 /usr/local/mysql/ 目录下

4. mysql 默认安装使用utf8 字符集

5. mysql 的数据和日志文件保存在 /var/mysql/ 对应目录下

6. mysql 的配置文件保存于/var/mysql/my.cnf


自行下载安装包:

m4-1.4.18.tar.gz

bison-2.5.tar.gz

cmake-2.8.8.tar.gz

mysql-5.6.10.tar.gz


首先可以查看下是否安装了 cmake # rpm -qa |grep cmake


安装 m4

# cd /usr/local/software# tar zxvf m4-1.4.18.tar.gz# cd m4-1.4.18# ./configure# make && make install


安装 cmake

# cd /usr/local/software# tar zxvf cmake-2.8.8.tar.gz# cd cmake-2.8.8# ./bootstrap# make && make install

安装 bison

# tar zxvf bison-2.5.tar.gz# cd bison-2.5# ./configure# make && make install

创建mysql用户及用户组

# groupadd mysql# useradd -r -g mysql mysql

编译安装 MySQL

cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_EXTRA_CHARSETS:STRING=utf8,gbk \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DENABLED_LOCAL_INFILE=1 \
-DENABLE_DOWNLOADS=1 \
-DMYSQL_DATADIR=/var/mysql/data \
-DMYSQL_USER=mysql

接下来,安装:
# make && make install

注意事项:

重新编译时,需要清除旧的对象文件和缓存信息。

# make clean# rm -f CMakeCache.txt# rm -rf /etc/my.cnf

参数说明:

-DCMAKE_INSTALL_PREFIX=/usr/local/mysql  //安装目录

-DINSTALL_DATADIR=/usr/local/mysql/data  //数据库存放目录

-DDEFAULT_CHARSET=utf8                   //使用utf8字符

-DDEFAULT_COLLATION=utf8_general_ci      //校验字符

-DEXTRA_CHARSETS=all                     //安装所有扩展字符集

-DENABLED_LOCAL_INFILE=1                 //允许从本地导入数据


分配权限:

# chmod +w /usr/local/mysql# chown -R mysql:mysql /usr/local/mysql# ln -s/usr/local/mysql/lib/libmysqlclient.so.18# /usr/lib/libmysqlclient.so.18

创建相应的目录:

# mkdir -p /var/mysql/# mkdir -p /var/mysql/data/# mkdir -p /var/mysql/log/

# chown -R mysql:mysql /var/mysql/# cd support-files/

# cp my-default.cnf /var/mysql/my.cnf# cp mysql.server /etc/init.d/mysqld

 配置启动MySQL

# /usr/local/mysql/scripts/mysql_install_db \--defaults-file=/var/mysql/my.cnf \--basedir=/usr/local/mysql \--datadir=/var/mysql/data \--user=mysql

Installing MySQL system tables...2017-02-07 10:29:30 26889 [Note] InnoDB: The InnoDB memory heap is disabled
2017-02-07 10:29:30 26889 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2017-02-07 10:29:30 26889 [Note] InnoDB: Compressed tables use zlib 1.2.3
2017-02-07 10:29:30 26889 [Note] InnoDB: CPU does not support crc32 instructions
2017-02-07 10:29:30 26889 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2017-02-07 10:29:30 26889 [Note] InnoDB: Completed initialization of buffer pool
2017-02-07 10:29:30 26889 [Note] InnoDB: Highest supported file format is Barracuda.
2017-02-07 10:29:30 26889 [Note] InnoDB: 128 rollback segment(s) are active.
2017-02-07 10:29:30 26889 [Note] InnoDB: Waiting for purge to start
2017-02-07 10:29:30 26889 [Note] InnoDB: 1.2.10 started; log sequence number 1626037
2017-02-07 10:29:30 26889 [Note] Binlog end
2017-02-07 10:29:30 26889 [Note] InnoDB: FTS optimize thread exiting.
2017-02-07 10:29:30 26889 [Note] InnoDB: Starting shutdown...
2017-02-07 10:29:31 26889 [Note] InnoDB: Shutdown completed; log sequence number 1626047
OK


Filling help tables...2017-02-07 10:29:31 26914 [Note] InnoDB: The InnoDB memory heap is disabled
2017-02-07 10:29:31 26914 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2017-02-07 10:29:31 26914 [Note] InnoDB: Compressed tables use zlib 1.2.3
2017-02-07 10:29:31 26914 [Note] InnoDB: CPU does not support crc32 instructions
2017-02-07 10:29:31 26914 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2017-02-07 10:29:31 26914 [Note] InnoDB: Completed initialization of buffer pool
2017-02-07 10:29:31 26914 [Note] InnoDB: Highest supported file format is Barracuda.
2017-02-07 10:29:31 26914 [Note] InnoDB: 128 rollback segment(s) are active.
2017-02-07 10:29:31 26914 [Note] InnoDB: Waiting for purge to start
2017-02-07 10:29:31 26914 [Note] InnoDB: 1.2.10 started; log sequence number 1626047
2017-02-07 10:29:32 26914 [Note] Binlog end
2017-02-07 10:29:32 26914 [Note] InnoDB: FTS optimize thread exiting.
2017-02-07 10:29:32 26914 [Note] InnoDB: Starting shutdown...
2017-02-07 10:29:33 26914 [Note] InnoDB: Shutdown completed; log sequence number 1626057
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:


  /usr/local/mysql/bin/mysqladmin -u root password 'new-password'
  /usr/local/mysql/bin/mysqladmin -u root -h iZ2zeg8zidyvg3jc1r0g6bZ password 'new-password'


Alternatively you can run:


  /usr/local/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 . ; /usr/local/mysql/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 with the ./bin/mysqlbug script!


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


WARNING: Found existing config file /usr/local/mysql/my.cnf on the system.
Because this file might be in use, it was not replaced,
but was used in bootstrap (unless you used --defaults-file)
and when you later start the server.
The new default config file was created as /usr/local/mysql/my-new.cnf,
please compare it with your file and take the changes you need.

将 mysql 加入开机启动

chmod +x /etc/init.d/mysqldvi /etc/init.d/mysqld (编辑此文件,查找并修改以下变量内容:)basedir=/usr/local/mysqldatadir=/var/mysql/datachkconfig --add mysqldchkconfig --level 345 mysqld on

启动 mysql

# service mysqld start

Starting MySQL...[OK]


设置root用户的密码

/usr/local/mysql/bin/mysqladmin -u root password 'wise83680688!@#'


使用root用户登录

# /usr/local/mysql/bin/mysql -uroot -p

Enter password:【输入密码】

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.6.10 Source distribution


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


至此,已经使用root用户和密码进行mysql的登录了。可以开始使用了。


0 0
原创粉丝点击