首页 > 学院 > 开发设计 > 正文

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

2019-11-09 13:34:13
字体:
来源:转载
供稿:网友

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

# 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 disabled2017-02-07 10:29:30 26889 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins2017-02-07 10:29:30 26889 [Note] InnoDB: Compressed tables use zlib 1.2.32017-02-07 10:29:30 26889 [Note] InnoDB: CPU does not support crc32 instructions2017-02-07 10:29:30 26889 [Note] InnoDB: Initializing buffer pool, size = 128.0M2017-02-07 10:29:30 26889 [Note] InnoDB: Completed initialization of buffer pool2017-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 start2017-02-07 10:29:30 26889 [Note] InnoDB: 1.2.10 started; log sequence number 16260372017-02-07 10:29:30 26889 [Note] Binlog end2017-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 1626047OKFilling help tables...2017-02-07 10:29:31 26914 [Note] InnoDB: The InnoDB memory heap is disabled2017-02-07 10:29:31 26914 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins2017-02-07 10:29:31 26914 [Note] InnoDB: Compressed tables use zlib 1.2.32017-02-07 10:29:31 26914 [Note] InnoDB: CPU does not support crc32 instructions2017-02-07 10:29:31 26914 [Note] InnoDB: Initializing buffer pool, size = 128.0M2017-02-07 10:29:31 26914 [Note] InnoDB: Completed initialization of buffer pool2017-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 start2017-02-07 10:29:31 26914 [Note] InnoDB: 1.2.10 started; log sequence number 16260472017-02-07 10:29:32 26914 [Note] Binlog end2017-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 1626057OKTo start mysqld at boot time you have to copysupport-files/mysql.server to the right place for your systemPLEASE 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_installationwhich will also give you the option of removing the testdatabases and anonymous user created by default.  This isstrongly 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.plPlease report any problems with the ./bin/mysqlbug script!The latest information about MySQL is available on the web at  http://www.mysql.comSupport MySQL by buying support/licenses at http://shop.mysql.comWARNING: 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 5Server version: 5.6.10 Source distributionCopyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '/h' for help. Type '/c' to clear the current input statement.mysql> 

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


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表