设为首页 收藏本站
查看: 527|回复: 0

[经验分享] MySQL-5.5.28编译安装

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2015-12-22 08:40:40 | 显示全部楼层 |阅读模式
编译安装MySQL-5.5

cmake的重要特性之一是其独立于源码(out-of-source)的编译功能,即编译工作可以在另一个指定的目录中而非源码目录中进行,这可以保证源码目录不受任何一次编译的影响,因此在同一个源码树上可以进行多次不同的编译,如针对于不同平台编译。

编译安装MySQL-5.5

一、安装开发环境
[iyunv@CentOS6 ~]#  yum install "Compatibility libraries" "Development tools" "gcc-c++"

二、编译安装cmake

[iyunv@CentOS6 ~]#  https://cmake.org/files/v3.4/cmake-3.4.1.tar.gz
[iyunv@CentOS6 ~]#  tar xf cmake-3.4.1.tar.gz
[iyunv@CentOS6 ~]#  cd cmake-3.4.1
[iyunv@CentOS6 cmake-3.4.1]#  ./bootstrap
[iyunv@CentOS6 cmake-3.4.1]#  make
[iyunv@CentOS6 cmake-3.4.1]#  make install


三、准备MySQL数据目录分区
[iyunv@CentOS6 ~]# fdisk /dev/sda

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-2610, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-2610, default 2610): +10G

Command (m for help): t
Selected partition 1
Hex code (type L to list codes): 8e
Changed system type of partition 1 to 8e (Linux LVM)

Command (m for help): p

Disk /dev/sda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x7dd89809

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1               1        1306    10490413+  8e  Linux LVM

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
[iyunv@CentOS6 ~]# cat /proc/partitions
major minor  #blocks  name

   8        0   20971520 sda
   8        1   10490413 sda1
   8       16   20971520 sdb
   8       17     512000 sdb1
   8       18   20458496 sdb2
253        0   18423808 dm-0
253        1    2031616 dm-1
[iyunv@CentOS6 ~]# pvcreate /dev/sda1
  Physical volume "/dev/sda1" successfully created
[iyunv@CentOS6 ~]# vgcreate myvg /dev/sda1
  Volume group "myvg" successfully created
[iyunv@CentOS6 ~]# lvcreate -L 5G -n mylv myvg
  Logical volume "mylv" created
[iyunv@CentOS6 ~]# mke2fs -j /dev/mapper/myvg-mylv
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
327680 inodes, 1310720 blocks
65536 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=1342177280
40 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
    32768, 98304, 163840, 229376, 294912, 819200, 884736

Writing inode tables: done                           
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 34 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

[iyunv@CentOS6 ~]# mkdir /mydata
[iyunv@CentOS6 ~]# vim /etc/fstab        
[iyunv@CentOS6 ~]# tail -1 /etc/fstab                        # 加入开机自启动列表
/dev/mapper/myvg-mylv   /mydata     ext3    defaults    0 0
[iyunv@CentOS6 ~]# mount -a
[iyunv@CentOS6 ~]# mkdir /mydata/data
[iyunv@CentOS6 ~]# ls /mydata
data  lost+found
[iyunv@CentOS6 ~]# chown -R  mysql.mysql /mydata/data
[iyunv@CentOS6 ~]# ll /mydata/data -d
drwxr-xr-x 2 mysql mysql 4096 Dec 19 20:34 /mydata/data



四、创建mysql用户
[iyunv@CentOS6 ~]#  groupadd -r mysql
[iyunv@CentOS6 ~]#  useradd -g mysql -r -d /mydata/data mysql

五、下载并编译安装mysql-5.5.28
[iyunv@CentOS6 tmp]#  wget https://downloads.mariadb.com/ar ... mysql-5.5.28.tar.gz
[iyunv@CentOS6 tmp]#  tar xf mysql-5.5.28.tar.gz
[iyunv@CentOS6 tmp]#  cd mysql-5.5.28
[iyunv@CentOS6 tmp]#  cmake . -LH                       # 查看安装选项
[iyunv@CentOS6 mysql-5.5.28]#  cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
          -DMYSQL_DATADIR=/mydata/data \
          -DSYSCONFDIR=/etc \
          -DWITH_INNOBASE_STORAGE_ENGINE=1 \
          -DWITH_ARCHIVE_STORAGE_ENGINE=1 \
          -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
          -DWITH_READLINE=1 \
          -DWITH_SSL=system \
          -DWITH_ZLIB=system \
          -DWITH_LIBWRAP=0 \
          -DMYSQL_UNIX_ADDR=/tmp/mysql.sock \
          -DDEFAULT_CHARSET=utf8 \
          -DDEFAULT_COLLATION=utf8_general_ci
Could NOT find Curses (missing:  CURSES_LIBRARY CURSES_INCLUDE_PATH)
[iyunv@CentOS6 mysql-5.5.28]#  yum install -y ncurses-devel
[iyunv@CentOS6 mysql-5.5.28]#  rm -f CMakeCache.txt
[iyunv@CentOS6 mysql-5.5.28]#  make
[iyunv@CentOS6 mysql-5.5.28]#  make install


六、MySQL的初始化工作
[iyunv@CentOS6 mysql-5.5.28]# cd /usr/local/mysql
[iyunv@CentOS6 mysql]# pwd
/usr/local/mysql
[iyunv@CentOS6 mysql]# ls
bin  COPYING  data  docs  include  INSTALL-BINARY  lib  man  mysql-test  README  scripts  share  sql-bench  support-files
[iyunv@CentOS6 mysql]# chown -R .mysql .
[iyunv@CentOS6 mysql]# ll
total 76
drwxr-xr-x  2 root mysql  4096 Dec 19 21:09 bin
-rw-r--r--  1 root mysql 17987 Aug 29  2012 COPYING
drwxr-xr-x  4 root mysql  4096 Dec 17 16:03 data
drwxr-xr-x  2 root mysql  4096 Dec 19 21:09 docs
drwxr-xr-x  3 root mysql  4096 Dec 19 21:09 include
-rw-r--r--  1 root mysql  7604 Aug 29  2012 INSTALL-BINARY
drwxr-xr-x  3 root mysql  4096 Dec 19 21:09 lib
drwxr-xr-x  4 root mysql  4096 Dec 12 10:39 man
drwxr-xr-x 10 root mysql  4096 Dec 19 21:09 mysql-test
-rw-r--r--  1 root mysql  2552 Aug 29  2012 README
drwxr-xr-x  2 root mysql  4096 Dec 19 21:09 scripts
drwxr-xr-x 27 root mysql  4096 Dec 17 13:50 share
drwxr-xr-x  4 root mysql  4096 Dec 19 21:09 sql-bench
drwxr-xr-x  2 root mysql  4096 Dec 19 21:09 support-files

[iyunv@CentOS6 mysql]# scripts/mysql_install_db --user=mysql --datadir=/mydata/data/
Installing MySQL system tables...
OK
Filling help tables...
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:

./bin/mysqladmin -u root password 'new-password'
./bin/mysqladmin -u root -h CentOS6.5 password 'new-password'

Alternatively you can run:
./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 . ; ./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!
        
[iyunv@CentOS6 mysql]# cp support-files/my-large.cnf /etc/my.cnf
[iyunv@CentOS6 mysql]# vim /etc/my.cnf
[iyunv@CentOS6 mysql]# grep -C 1 "datadir" /etc/my.cnf    # 修改第一项,增加第二和第三项
thread_concurrency = 8
datadir = /mydata/data
innodb_file_per_table = 1
[iyunv@CentOS6 mysql]# cp support-files/mysql.server /etc/rc.d/init.d/mysqld
[iyunv@CentOS6 mysql]# chkconfig --add mysqld
[iyunv@CentOS6 mysql]# chkconfig --list mysqld
mysqld             0:off   1:off   2:on    3:on    4:on    5:on    6:off

七、导出MySQL的PATH环境变量与头文件
[iyunv@CentOS6 mysql]# echo 'export PATH=$PATH:/usr/local/mysql/bin' > /etc/profile.d/mysqld.sh
[iyunv@CentOS6 mysql]# . /etc/profile.d/mysqld.sh
[iyunv@CentOS6 mysql]# ln -sv /usr/local/mysql/include  /usr/include/mysql

八、启动之后连接MySQL,删除匿名用户、设置root密码及远程访问授权
[iyunv@CentOS6 mysql]# service mysqld start
Starting MySQL... SUCCESS!

(1)、删除匿名用户
[iyunv@CentOS6 mysql]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.5.28-log 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> SELECT User,Host,Password FROM mysql.user;
+------+-----------+----------+
| User | Host      | Password |
+------+-----------+----------+
| root | localhost |          |
| root | CentOS6.5 |          |
| root | 127.0.0.1 |          |
| root | ::1       |          |
|      | localhost |          |
|      | CentOS6.5 |          |
+------+-----------+----------+
5 rows in set (0.00 sec)

mysql> DROP USER ''@'CentOS6.5';
Query OK, 0 rows affected (0.01 sec)

mysql> DROP USER ''@'localhost';
Query OK, 0 rows affected (0.01 sec)

mysql> exit
Bye

(2)、设置root用户密码
mysql> UPDATE mysql.user SET Password=PASSWORD('redhat') WHERE User='root';
Query OK, 4 rows affected (0.06 sec)
Rows matched: 4  Changed: 4  Warnings: 0

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

mysql> exit
Bye

(3)、远程访问授权
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'redhat';
Query OK, 0 rows affected (0.00 sec)

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

mysql> exit
Bye




运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-154540-1-1.html 上篇帖子: keepalived+mysql+centos6.4 简单配置 下篇帖子: MySQL 基础知识理论篇
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表