码迷,mamicode.com
首页 > 数据库 > 详细

MySQL安装方式总结

时间:2015-07-05 22:32:01      阅读:360      评论:0      收藏:0      [点我收藏+]

标签:

MySQL的安装方式一共有4种
  1. yum 安装
  2. MySQL 5.1 为 make 安装
  3. MySQL 5.5 为 cmake 安装
  4. 二进制的方式安装 MySQL
  5. MySQL 的初始化设置

基础环境
  1. [root@mysql ~]# cat /etc/redhat-release 
  2. CentOS release 6.6 (Final)
  3. [root@mysql ~]# uname -r
  4. 2.6.32-504.el6.x86_64
  5. [root@mysql ~]# uname -m
  6. x86_64
  7. yum groupinstall "Base" "Compatibility libraries" "Development tools" "Dial-up Networking Support" "Performance Tools" "Performance Tools"




一、yum 安装

  1. yum install mysql-server

二、MySQL 5.1 的 make 安装

  1. # 2.1 创建用户与mysql数据存放目录
  2. useradd -M -s /sbin/nologin mysql
  3. mkdir /data
  4. chown mysql.mysql /data
  5. # 2.2 安装必要包,下载解压
  6. yum install ncurses-devel -y #没安装包会有这个报错:checking for termcap functions library... configure: error: No curses/termcap library found
  7. mkdir /home/test
  8. cd /home/test/tools
  9. wget http://cdn.mysql.com/Downloads/MySQL-5.1/mysql-5.1.73.tar.gz
  10. tar xf mysql-5.1.73.tar.gz
  11. cd mysql-5.1.73
  12. # 2.3 生成Makefile,编译,安装
  13. ./configure \
  14. --prefix=/application/mysql-5.1.73 \
  15. --with-unix-socket-path=/application/mysql-5.1.73/tmp/mysql.sock \
  16. --localstatedir=/application/mysql-5.1.73/data \
  17. --enable-assembler \
  18. --enable-thread-safe-client \
  19. --with-mysqld-user=mysql \
  20. --with-big-tables \
  21. --without-debug \
  22. --with-pthread \
  23. --enable-assembler \
  24. --with-extra-charsets=complex \
  25. --with-readline \
  26. --with-ssl \
  27. --with-embedded-server \
  28. --enable-local-infile \
  29. --with-plugins=partition,innobase \
  30. --with-mysqld-ldflags=-all-static \
  31. --with-client-ldflags=-all-static
  32. make -j 2 && make install
  33. # 提示:可以通过 echo $? 来查看编译安装过程中是否出错

  34. # 2.4 对mysql-5.1.73创建软连接
  35. ln -s /application/mysql-5.1.73/ /application/mysql

  36. # 2.5 提供配置文件
  37. \cp /application/mysql/share/mysql/my-large.cnf /etc/my.cnf
  38. #在mysqld中添加 skip_name_resolve =on innodb_file_per_table = on

  39. # 2.6 初始化mysql
  40. /application/mysql/bin/mysql_install_db --basedir=/application/mysql --datadir=/data/ --user=mysql

  41. # 2.7 提供 SysV 脚本
  42. cp /application/mysql/share/mysql/mysql.server /etc/init.d/mysqld
  43. chmod +x /etc/init.d/mysqld
  44. # 修改basedir和datadir
  45. sed -i ‘46s#\(basedir=\).*#\1/application/mysql#‘ /etc/rc.d/init.d/mysqld
  46. sed -i ‘47s#\(datadir=\).*#\1/data#‘ /etc/rc.d/init.d/mysqld
  47. chkconfig --add mysqld
  48. chkconfig mysqld off
  49. chkconfig --list mysqld

  50. # 2.8 启动mysql
  51. /etc/init.d/mysqld start
  52. # 2.9 将mysql的路径加入环境变量
  53. echo "PATH=/application/mysql/bin/:$PATH" > /etc/profile.d/mysql.sh
  54. source /etc/profile.d/mysql.sh

  55. # 2.10 输出mysql的库文件给系统的查找路径
  56. echo ‘/application/mysql/lib‘ > /etc/ld.so.conf.d/mysql.conf
  57. ldconfig

  58. # 2.11 输出mysql的头文件至系统头文件路径
  59. ln -s /application/mysql/include/mysql/ /usr/include/mysql

  60. # 2.12 将编译的软件man手册加入系统
  61. cat >> /etc/man.config << EOF
  62. # start 20150705 by test
  63. MANPATH /application/mysql/share/man
  64. # end 20150705 by test
  65. EOF

三、MySQL 5.5 的 make 安装

  1. # 2.1 创建用户与mysql数据存放目录
  2. useradd -M -s /sbin/nologin mysql
  3. mkdir /data
  4. chown mysql.mysql /data

  5. # 2.2 安装必要包,下载解压
  6. yum install cmake ncurses-devel -y
  7. wget http://mirrors.opencas.cn/mariadb/mariadb-5.5.44/source/mariadb-5.5.44.tar.gz
  8. tar xf mariadb-5.5.44
  9. cd mariadb-5.5.44

  10. # 2.3 编译安装(cmake --> make --> make install)
  11. cmake . \
  12. -DCMAKE_INSTALL_PREFIX=/application/mariadb-5.5.44 \
  13. -DMYSQL_DATADIR=/data \
  14. -DMYSQL_UNIX_ADDR=/application/mariadb-5.5.44/tmp/mysql.sock \
  15. -DDEFAULT_CHARSET=utf8 \
  16. -DDEFAULT_COLLATION=utf8_general_ci \
  17. -DEXTRA_CHARSETS=gbk,gb2312,utf8,ascii \
  18. -DENABLED_LOCAL_INFILE=ON \
  19. -DWITH_INNOBASE_STORAGE_ENGINE=1 \
  20. -DWITH_FEDERATED_STORAGE_ENGINE=1 \
  21. -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
  22. -DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 \
  23. -DWITHOUT_PARTITION_STORAGE_ENGINE=1 \
  24. -DWITH_FAST_MUTEXES=1 \
  25. -DWITH_ZLIB=bundled \
  26. -DENABLED_LOCAL_INFILE=1 \
  27. -DWITH_READLINE=1 \
  28. -DWITH_EMBEDDED_SERVER=1 \
  29. -DWITH_DEBUG=0
  30. make -j 4 && make install

  31. # 2.4 创建软连接
  32. ln -s /application/mariadb-5.5.44/ /application/mariadb

  33. # 2.5 提供配置文件
  34. cd /application/mariadb/
  35. \cp support-files/my-large.cnf /etc/my.cnf

  36. # 2.6 初始化 mariadb
  37. scripts/mysql_install_db --user=mysql --basedir=/application/mariadb/ --datadir=/data/

  38. # 2.7 提供 SysV 脚本
  39. cp support-files/mysql.server /etc/init.d/mysqld
  40. chmod +x /etc/init.d/mysqld
  41. # 2.8 启动 mariadb
  42. /etc/init.d/mysqld start

  43. # 2.9 将 mariadb 的路径加入环境变量
  44. echo "PATH=/application/mariadb/bin:$PATH" > /etc/profile.d/mysql.sh
  45. source /etc/profile.d/mysql.sh
  46. # 2.10 输出 mariadb 的库文件给系统的查找路径
  47. echo ‘/application/mariadb/lib/‘ > /etc/ld.so.conf.d/mysql.conf
  48. ldconfig

  49. # 2.11 输出 mariadb 的头文件至系统头文件路径
  50. ln -s /application/mariadb/include/mysql/ /usr/include/mysql

  51. # 2.12 将编译的软件man手册加入系统
  52. cat >> /etc/man.config << EOF
  53. # start 20150705 by test
  54. MANPATH /application/mariadb/man/
  55. # end 20150705 by test
  56. EOF

四、二进制的方式安装 MySQL

  1. # 2.1 创建用户与mysql数据存放目录
  2. useradd -M -s /sbin/nologin mysql
  3. mkdir /data
  4. chown mysql.mysql /data
  5. # 2.2 下载解压并移动到指定目录
  6. mkdir /home/test
  7. cd /home/test/
  8. wget http://mirrors.opencas.cn/mariadb/mariadb-5.5.44/bintar-linux-glibc_214-x86_64/mariadb-5.5.44-x86_64.tar.gz
  9. tar xf mariadb-5.5.44-linux-x86_64.tar.gz
  10. mkdir /application
  11. mv mariadb-5.5.44-linux-x86_64 /application

  12. # 2.3 对创建软连接
  13. ln -s /application/mariadb-5.5.44-linux-x86_64 /application/mariadb

  14. # 2.4 初始化mariadb
  15. cd /application/mariadb
  16. scripts/mysql_install_db --user=mysql --basedir=/application/mariadb --datadir=/data/

  17. # 2.5 提供配置文件
  18. \cp /application/mariadb/support-files/my-large.cnf /etc/my.cnf

  19. # 2.6 提供 SysV 脚本
  20. cp /application/mariadb/support-files/mysql.server /etc/init.d/mysqld
  21. sed -i ‘46s#\(basedir=\).*#\1/application/mariadb#‘ /etc/rc.d/init.d/mysqld
  22. sed -i ‘47s#\(datadir=\).*#\1/data#‘ /etc/rc.d/init.d/mysqld
  23. chmod +x /etc/init.d/mysqld

  24. # 2.7 提供环境变量
  25. echo "PATH=/application/mariadb/bin/:$PATH" > /etc/profile.d/mysql.sh
  26. source /etc/profile.d/mysql.sh
  27. # 2.8 启动mysql
  28. /etc/init.d/mysqld start

输出库文件、头文件、man手册和以上5.5 的编译安装一样

五、mysql的初始化设置(对以上安装都适用)

  1. # 登陆
  2. mysql
  3. MariaDB [(none)]> show databases;
  4. +--------------------+
  5. | Database |
  6. +--------------------+
  7. | information_schema |
  8. | mysql |
  9. | performance_schema |
  10. | test |
  11. +--------------------+

  12. MariaDB [(none)]> select user,host from mysql.user;
  13. +------+-----------+
  14. | user | host |
  15. +------+-----------+
  16. | root | 127.0.0.1 |
  17. | root | ::1 |
  18. | | localhost |
  19. | root | localhost |
  20. | | mysql |
  21. | root | mysql |
  22. +------+-----------+
  23. 6 rows in set (0.03 sec)

  24. # 删除多余的库和用户
  25. mysql -e "drop database test;"
  26. mysql -e "drop user ‘root‘@‘::1‘;"
  27. mysql -e "drop user ‘‘@‘localhost‘"
  28. mysql -e "delete from mysql.user where user=‘‘ and host=‘mysql‘;"
  29. mysql -e "delete from mysql.user where user=‘root‘ and host=‘mysql‘;"
  30. mysql -e "select user,host from mysql.user;"
  31. mysql -e "show databases;"
  32. # 设置密码
  33. mysqladmin -u root password ‘123‘
  34. # 设置完密码再次登陆
  35. mysql -uroot -p123 -hlocalhost

  36. # 修改密码
  37. mysqladmin -u root -p123 password 123456


MySQL安装方式总结

标签:

原文地址:http://www.cnblogs.com/kwstars/p/4f82462b7fb8c6106e662ebc6549e0c6.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
分享档案
周排行
mamicode.com排行更多图片
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!