MySQL 安装

Mysql安装:

  1. 1、通过二进制的方式安装
  2. 二进制安装方式中,包括rpm版本以及glibc版本。
  3. rpm版本就是在特定linux版本下编译的,如果你的linux版本匹配,就可以安装;
  4. glibc版本是基于特定的glibc版本编译的;
  5. glibcGNU发布的libc库,即c运行库。glibclinux系统中最底层的api,几乎其它任何运行库都会依赖于glibc
  6. 优点:安装和维护都比较方便,不需要编译。
  7. 缺点:可定制性差,可移植性差,不灵活
  8.  
  9. 2、通过源代码编译的安装(mysql-xx.tar.gz
  10. 优点:可定制性强(安装可以根据用户的需求,只安装所需要的功能)
  11. 缺点:安装复杂,所需要的时间比二进制的安装要长得多
  12.  
  13. 3、构建自己的二进制rpm
  14. 优点:根据需求定制成自己的rpm包,方便安装维护。
  15. 缺点:前期构建耗时较长,相对比较复杂

MySQL国内镜像下载地址:
http://mirrors.sohu.com/mysql/

http://mirrors.ustc.edu.cn/mysql-ftp/Downloads/

开源镜像站点汇总

http://mirrors.ustc.edu.cn/

二进制的rpm安装(红帽自带)

  1. 一、redhat mysql(RPM) 光盘中mysql老旧,漏洞多,如果一定要使用此版本,请到红帽的源码目录树中下载最新版本
  2. # yum list|grep ^mysql
  3. mysql.x86_64 客户端
  4. mysql-bench.x86_64 压力测试工具包
  5. mysql-connector-java.noarch 连接器
  6. mysql-connector-odbc.x86_64
  7. mysql-devel.i686 开发包
  8. mysql-devel.x86_64
  9. mysql-libs.i686 库包(*.dll),可以让其他第三方程序调用这些库文件,扩充软件功能
  10. mysql-libs.x86_64
  11. mysql-server.x86_64 服务器
  12. mysql-test.x86_64 测试库
  13.  
  14. 安装服务端和客户端软件:
  15. # yum -y install mysql mysql-server
  16.  
  17. 启动服务:
  18. mysql启动原理
  19. 执行mysqld(服务端命)
  20. ----> 根据参数读取配置文件或者直接给命令传递参数
  21. ----> 读取相应的数据文件和其他的物理文件(日志文件等)
  22. ----> 生成socket文件和在相应的端口上进行监听
  23. 说明:rhel系统自动的数据库的启动脚本会判断数据目录是否为空,如果为空,它会自动初始化
  24.  
  25. # service mysqld start
  26.  
  27. 测试是否启动ok
  28. # lsof -i:3306
  29. COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
  30. mysqld 7321 mysql 10u IPv4 54236 0t0 TCP *:mysql (LISTEN)
  31. # netstat -nltp|grep 3306
  32. tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 7321/mysqld
  33.  
  34. # mysql
  35. Welcome to the MySQL monitor. Commands end with ; or \g.
  36. Your MySQL connection id is 2
  37. Server version: 5.1.71 Source distribution
  38.  
  39. mysql> show databases; 查看有哪些库
  40. +--------------------+
  41. | Database |
  42. +--------------------+
  43. | information_schema |
  44. | mysql |
  45. | test |
  46. +--------------------+
  47. 3 rows in set (0.00 sec)
  48.  
  49. information_schema数据库:
  50. 对象信息数据库,其中保存着关于MySQL服务器所维护的所有其他数据库的信息。在INFORMATION_SCHEMA中,有数个只读表。它们实际上是视图,而不是基本表,因此,你将无法看到与之相关的任何文件。
  51. 视图:是一个虚表,即视图所对应的数据不进行实际存储,数据库中只存储视图的定义,在对视图的数据进行操作时,系统根据视图的定义去操作与视图相关联的基本表。
  52. mysql数据库:
  53. 这个是mysql的核心数据库,主要负责存储数据库的用户、权限设置、关键字等mysql自己需要使用的控制和管理信息;不可以删除,也不要轻易修改这个数据库里面的表息。
  54. test数据库:
  55. 这个是安装时候创建的一个测试数据库,和它的名字一样,是一个完全的空数据库,没有任何表,可以删除。

二进制的rpm安装

  1. 默认读取的首选配置文件 /etc/my.cnf
  2. # cat /etc/my.cnf
  3. [mysqld] 用中括号括起来的叫参数组,用来针对不同的工具设定参数
  4. datadir=/var/lib/mysql 数据文件存放的目录
  5. socket=/var/lib/mysql/mysql.sock socket文件是用于本地连接mysql数据库的接口文件,远程连接的话就要通过TCPIP协议
  6. user=mysql 管理mysql的系统用户
  7. # Disabling symbolic-links is recommended to prevent assorted security risks 禁止使用符号链接,防止安全隐患
  8. symbolic-links=0
  9.  
  10. [mysqld_safe]
  11. log-error=/var/log/mysqld.log # 错误日志文件
  12. pid-file=/var/run/mysqld/mysqld.pid # pid文件
  13.  
  14. 注意:pid文件和socket文件是服务启动成功后才会有的

修改配置文件

官方rpm包安装

  1. 二、mysql AB (RPM) -mysql官方的RPM包,提供版本比较多,像suse/redhat/oracle linux
  2.  
  3. MySQL-client-5.6.19-1.el6.x86_64.rpm 客户端
  4. MySQL-devel-5.6.19-1.el6.x86_64.rpm 开发工具包(其他软件需要调用到mysql的头文件或者库文件时安装)egproxy、监控软件等
  5. MySQL-embedded-5.6.19-1.el6.x86_64.rpm 嵌入式工具包
  6. MySQL-server-5.6.19-1.el6.x86_64.rpm 服务端
  7. MySQL-shared-5.6.19-1.el6.x86_64.rpm 工具包
  8. MySQL-shared-compat-5.6.19-1.el6.x86_64.rpm
  9. MySQL-test-5.6.19-1.el6.x86_64.rpm 测试库
  10.  
  11. 安装服务端和客户端:
  12. 1> 卸载掉已经安装的mysql
  13.  
  14. # rpm -aq|grep mysql|xargs rpm -e --nodeps
  15. # rm -rf /var/lib/mysql/*
  16. 或者
  17. # rpm -e `rpm -aq|grep mysql` --nodeps
  18. 2> 安装5.6.19rpm
  19.  
  20. # rpm -ivh MySQL-client-5.6.19-1.el6.x86_64.rpm
  21. Preparing... ########################################### [100%]
  22. 1:MySQL-client ########################################### [100%]
  23. # rpm -ivh MySQL-server-5.6.19-1.el6.x86_64.rpm
  24. Preparing... ########################################### [100%]
  25. 1:MySQL-server ########################################### [100%]
  26.  
  27. # cat /root/.mysql_secret 默认root用户的密码
  28. # The random password set for the root user at Wed Aug 16 11:10:58 2017 (local time): KTVnqzD2lUVvMBYP
  29.  
  30. # /usr/bin/mysql_secure_installation
  31. Enter current password for root (enter for none):
  32. ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
  33.  
  34. 原因:数据库没有启动
  35. 解决:启动数据库
  36.  
  37. # /usr/bin/mysql_secure_installation 对数据库做安全配置
  38.  
  39. NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
  40. SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
  41.  
  42. In order to log into MySQL to secure it, we'll need the current
  43. password for the root user. If you've just installed MySQL, and
  44. you haven't set the root password yet, the password will be blank,
  45. so you should just press enter here.
  46.  
  47. Enter current password for root (enter for none):
  48. ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
  49. Enter current password for root (enter for none):
  50. OK, successfully used password, moving on...
  51.  
  52. Setting the root password ensures that nobody can log into the MySQL
  53. root user without the proper authorisation.
  54.  
  55. You already have a root password set, so you can safely answer 'n'.
  56.  
  57. Change the root password? [Y/n] y 是否更改mysql数据库的root密码
  58. New password:
  59. Re-enter new password:
  60. Password updated successfully!
  61. Reloading privilege tables..
  62. ... Success!
  63.  
  64. By default, a MySQL installation has an anonymous user, allowing anyone
  65. to log into MySQL without having to have a user account created for
  66. them. This is intended only for testing, and to make the installation
  67. go a bit smoother. You should remove them before moving into a
  68. production environment.
  69.  
  70. Remove anonymous users? [Y/n] y 是否移除匿名用户
  71. ... Success!
  72.  
  73. Normally, root should only be allowed to connect from 'localhost'. This
  74. ensures that someone cannot guess at the root password from the network.
  75.  
  76. Disallow root login remotely? [Y/n] n 是否禁止root用户远程登录|生产禁止
  77. ... skipping.
  78.  
  79. By default, MySQL comes with a database named 'test' that anyone can
  80. access. This is also intended only for testing, and should be removed
  81. before moving into a production environment.
  82.  
  83. Remove test database and access to it? [Y/n] y 移除test库
  84. - Dropping test database...
  85. ... Success!
  86. - Removing privileges on test database...
  87. ... Success!
  88.  
  89. Reloading the privilege tables will ensure that all changes made so far
  90. will take effect immediately.
  91.  
  92. Reload privilege tables now? [Y/n] y 刷新授权表
  93. ... Success!
  94.  
  95. All done! If you've completed all of the above steps, your MySQL
  96. installation should now be secure.
  97.  
  98. Thanks for using MySQL!
  99.  
  100. Cleaning up...
  101.  
  102. 启动数据库:
  103. # service mysql start
  104. Starting MySQL.... [ OK ]
  105.  
  106. mysql> show databases;
  107. +--------------------+
  108. | Database |
  109. +--------------------+
  110. | information_schema |
  111. | mysql |
  112. | performance_schema |
  113. +--------------------+
  114.  
  115. 说明:
  116. mysql5.1版本后,官方所发布的mysql的服务名称发生了变化,以前是mysqld现在是mysql,但是redhat 发行版本中依然是mysqld
  117.  
  118. 安全配置:
  119. # mysql_secure_installation
  120.  
  121. 说明:默认情况下mysql数据库安装在/usr下;数据文件在/var/lib/mysql

mysql官方的RPM包安装

双版本安装

参考:https://www.cnblogs.com/yanjieli/p/9777466.html

glibc二进制包安装

参考:https://www.cnblogs.com/yanjieli/p/11950100.html

yum源安装

  1. #下载mysql源安装包
  2. [root@7ab22243eaf9 /]# wget http://dev.mysql.com/get/mysql57-community-release-el6-8.noarch.rpm
  3.  
  4. #安装mysql源
  5. [root@7ab22243eaf9 /]# yum -y localinstall mysql57-community-release-el6-8.noarch.rpm
  6.  
  7. #检查mysql源是否安装成功
  8. [root@7ab22243eaf9 /]# yum repolist enabled |grep "mysql.*-community.*"
  9.  
  10. #改变默认安装的mysql版本。比如要安装5.6版本,将5.7源的enabled=1改成enabled=0。然后再将5.6源的enabled=0改成enabled=1即可。
  11. [root@7ab22243eaf9 /]# vim /etc/yum.repos.d/mysql-community.repo #这一步可以省略,默认是安装最高版本
  12. [mysql56-community]
  13. name=MySQL 5.6 Community Server
  14. baseurl=http://repo.mysql.com/yum/mysql-5.6-community/el/7/$basearch/
  15. enabled=0
  16. gpgcheck=1
  17. gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
  18.  
  19. [mysql57-community]
  20. name=MySQL 5.7 Community Server
  21. baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/$basearch/
  22. enabled=1
  23. gpgcheck=1
  24. gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
  25.  
  26. #安装mysql
  27. [root@7ab22243eaf9 /]# yum -y install mysql-community-server
  28.  
  29. #启动mysql并设置开机自启动
  30. [root@7ab22243eaf9 /]# service mysqld start
  31. Initializing MySQL database: [ OK ]
  32. Starting mysqld: [ OK ]
  33. [root@7ab22243eaf9 /]# chkconfig --add mysqld
  34. [root@7ab22243eaf9 /]# chkconfig --level 35 mysqld on
  35.  
  36. #查看初始密码,存放在/var/log/mysqld.log文件里面
  37. [root@7ab22243eaf9 /]# grep "temporary password" /var/log/mysqld.log
  38. 2019-11-22T06:54:39.570807Z 1 [Note] A temporary password is generated for root@localhost: Rw)6ImidXYGq
  39.  
  40. #连接mysql进行修改密码
  41. [root@7ab22243eaf9 /]# mysql -p
  42. Enter password: Rw)6ImidXYGq #这里输入上面的密码
  43. mysql> alter user 'root'@'localhost' identified by "MyNewP@sswd1";
  44. Query OK, 0 rows affected (0.00 sec)
  45. mysql> \q
  46.  
  47. #使用新密码进行测试
  48. [root@7ab22243eaf9 /]# mysql -pMyNewP@sswd1 -e "show databases;"
  49. mysql: [Warning] Using a password on the command line interface can be insecure.
  50. +--------------------+
  51. | Database |
  52. +--------------------+
  53. | information_schema |
  54. | mysql |
  55. | performance_schema |
  56. | sys |
  57. +--------------------+

centos6 yum安装MySQL5.6或者5.7

  1. #下载mysql源安装包
  2. [root@2a2d63b53730 /]# wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
  3.  
  4. #安装mysql源
  5. [root@2a2d63b53730 /]# yum -y localinstall mysql57-community-release-el7-8.noarch.rpm
  6.  
  7. #检查mysql源是否安装成功
  8. [root@2a2d63b53730 /]# yum repolist enabled |grep "mysql.*-community.*"
  9.  
  10. #安装mysql
  11. [root@2a2d63b53730 /]# yum -y install mysql-community-server
  12.  
  13. #启动mysql并设置开机自启动
  14. [root@2a2d63b53730 /]# systemctl enable mysqld
  15. [root@2a2d63b53730 /]# systemctl start mysqld
  16.  
  17. #查看初始密码,存放在/var/log/mysqld.log文件里面
  18. [root@2a2d63b53730 /]# grep "temporary password" /var/log/mysqld.log
  19. 2019-11-22T08:07:50.088821Z 1 [Note] A temporary password is generated for root@localhost: 9HveX=1pp2&o
  20.  
  21. #连接mysql进行修改密码
  22. [root@2a2d63b53730 /]# mysql -p
  23. Enter password: 9HveX=1pp2&o #输入上面的密码
  24. mysql> alter user 'root'@'localhost' identified by "MyNewP@sswd1";
  25. Query OK, 0 rows affected (0.01 sec)
  26. mysql> \q
  27.  
  28. #使用新密码进行测试
  29. [root@2a2d63b53730 /]# mysql -pMyNewP@sswd1 -e "show databases;"
  30. mysql: [Warning] Using a password on the command line interface can be insecure.
  31. +--------------------+
  32. | Database |
  33. +--------------------+
  34. | information_schema |
  35. | mysql |
  36. | performance_schema |
  37. | sys |
  38. +--------------------+

centos7 yum安装MySQL5.6或者5.7

源码包编译安装

  1. 4、源码包安装 5.6.25
  2. install_dir: /mysql25
  3. data_dir: /mysql25/data
  4. socket:/mysql25/mysql.sock
  5. port:3308
  6. config_file:/mysql25/etc/my.cnf
  7.  
  8. # md5sum mysql-5.6.25.tar.gz
  9. 37664399c91021abe070faa700ecd0ed mysql-5.6.25.tar.gz
  10.  
  11. 步骤:
  12. 1、创建相应的数据目录
  13. mkdir /mysql25/data -p
  14.  
  15. 2、解压相应的软件包到指定的临时目录里(/usr/src
  16. # tar -xf mysql-5.6.25.tar.gz -C /usr/src/
  17. # cd /usr/src/mysql-5.6.25/
  18.  
  19. 3、根据需求进行配置
  20. 参考官方文档
  21. 默认情况下载当前目录下直接可以配置
  22. shell> cmake . -LAH 查看所有支持的配置选项
  23. shell> cmake .
  24.  
  25. CMAKE_INSTALL_PREFIX /usr/local/mysql 安装路径
  26. DEFAULT_CHARSET latin1 拉丁 默认字符集
  27. DEFAULT_COLLATION latin1_swedish_ci 指定服务器默认的校对规则(排序规则)
  28. ENABLED_LOCAL_INFILE OFF 是否开启内部加载外部文件功能 默认off 1代表开启0代表关闭
  29. MYSQL_DATADIR 数据文件目录
  30. SYSCONFDIR 初始化参数文件目录(主配置文件路径(默认优先去/etc目录去找))
  31. MYSQL_TCP_PORT 服务端口号,默认3306
  32. MYSQL_UNIX_ADDR socket文件路径,默认/tmp/mysql.sock
  33. WITHOUT_xxx_STORAGE_ENGINE 指定不编译的存储引擎
  34. WITH_xxx_STORAGE_ENGINE 指定静态编译到mysql的存储引擎,MyISAMMERGEMEMBER以及CSV四种引擎默认即被编译至服务器,不需要特别指定。
  35. WITH_EXTRA_CHARSETS 扩展字符集
  36.  
  37. 字符集与字符编码
  38. 字符是各种文字和符号的总称,包括各个国家文字、标点符号、图形符号、数字等。字符集是多个字符的集合,字符集种类较多,每个字符集包含的字符个数不同,
  39. 计算机要准确的处理各种字符集文字,需要进行字符编码,以便计算机能够识别和存储各种文字。也就是说字符编码是字符集的实现方式。
  40. 但需要注意的是:有的字符编码和字符集的名称是一致的。
  41.  
  42. 常见的字符集
  43.     Unicode:也叫统一字符集,它包含了几乎世界上所有的已经发现且需要使用的字符(如中文、日文、英文、德文等)。
  44.     ASCII:早期的计算机系统只能处理英文,所以ASCII也就成为了计算机的缺省字符集,包含了英文所需要的所有字符。
  45.     GB2312:中文字符集,包含ASCII字符集。ASCII部分用单字节表示,剩余部分用双字节表示。
  46.     GBKGB2312的扩展,但完整包含了GB2312的所有内容。
  47.     GB18030GBK字符集的超集,常叫大汉字字符集,也叫CJKChineseJapaneseKorea)字符集,包含了中、日、韩三国语言中的所有字符。
  48. 常见的字符编码:
  49. UTF-8 UTF-16 UCS-2 UCS-4
  50. GBK/GB2312
  51. GB18030
  52.  
  53. 字符编码 每个字符字节数
  54. ASCII 1
  55. UCS-2(Unicode) 2
  56. UCS-4(Unicode) 4
  57. UTF-8(Unicode) 1 - 6
  58. UTF-16(Unicode) 2 - 4
  59. GBK/GB2312(中文) 1 - 2
  60. GB18030(CJK) 1- 4
  61. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  62.  
  63. 编写cmake脚本:
  64. vim cmake.sh
  65. #!/bin/bash
  66. cmake . \
  67. -DCMAKE_INSTALL_PREFIX=/mysql25 \
  68. -DENABLED_LOCAL_INFILE=1 \
  69. -DMYSQL_DATADIR=/mysql25/data \
  70. -DSYSCONFDIR=/mysql25/etc \
  71. -DWITH_INNOBASE_STORAGE_ENGINE=1 \
  72. -DWITH_PARTITION_STORAGE_ENGINE=1 \
  73. -DMYSQL_UNIX_ADDR=/mysql25/mysql.sock \
  74. -DDEFAULT_CHARSET=utf8 \
  75. -DDEFAULT_COLLATION=utf8_general_ci \
  76. -DWITH_EXTRA_CHARSETS=all \
  77. -DMYSQL_USER=mysql \
  78. -DMYSQL_TCP_PORT=3308
  79.  
  80. chmod +x cmake.sh
  81.  
  82. # ./cmake.sh
  83. ./cmake.sh: line 2: cmake: command not found
  84.  
  85. yum -y install cmake
  86. # ./cmake.sh
  87. -- Could NOT find Curses (missing: CURSES_LIBRARY CURSES_INCLUDE_PATH)
  88. CMake Error at cmake/readline.cmake:85 (MESSAGE):
  89. Curses library not found. Please install appropriate package,
  90.  
  91. remove CMakeCache.txt and rerun cmake.On Debian/Ubuntu, package name is libncurses5-dev, on Redhat and derivates it is ncurses-devel.
  92. Call Stack (most recent call first):
  93.  
  94. # yum -y install ncurses-devel
  95.  
  96. 说明:如果第一次配置出错,再次配置前删掉上一次的缓存文件
  97. rm -f CMakeCache.txt
  98.  
  99. 4、编译
  100. 指定cpu个数编译
  101. cat /proc/cpuinfo |grep processor|wc -l
  102. make -j 2--------------------------指定多个CPU快速表编译
  103.  
  104. 5、安装
  105. make install
  106.  
  107. 6、后续配置
  108.  
  109. 初始化数据库(安装默认的库和表):
  110. cd /mysql25
  111.  
  112. # ./mysql_install_db --help
  113. --no-defaults:不要从任何的配置文件中读取相应的参数,忽略掉mysql安装过程中的默认配置,如创建默认用户并设置默认密码等
  114.  
  115. # ./mysql_install_db --basedir=/mysql25 --datadir=/mysql25/data --no-defaults --user=mysql
  116.  
  117. 启动数据库:
  118. 报错:
  119. # service mysql25 start
  120. Starting MySQL.The server quit without updating PID file (/mysql/data/vm1.uplook.com.pid).[FAILED]
  121. 解决:
  122. chown mysql.mysql /mysql -R
  123.  
  124. 环境变量:
  125. export PATH=$PATH:/usr/local/mysql/bin
  126.  
  127. # mysql
  128. ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
  129. [root@vm1 data]# mysql --socket=/data/mysql.sock
  130.  
  131. # ln -s /data/mysql.sock /var/lib/mysql/mysql.sock
  132.  
  133. # mysql
  134. Welcome to the MySQL monitor. Commands end with ; or \g.
  135. Your MySQL connection id is 2
  136. Server version: 5.6.25 Source distribution
  137.  
  138. Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
  139.  
  140. Oracle is a registered trademark of Oracle Corporation and/or its
  141. affiliates. Other names may be trademarks of their respective
  142. owners.
  143.  
  144. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  145.  
  146. mysql> exit
  147. Bye
  148.  
  149. ##############################################################################
  150.  
  151. 总结:
  152. 1、修改配置文件重新指定了pid文件的路径
  153. 2、mysql的数据目录的权限问题或者pid文件的权限
  154. 3、mysql数据库没有正常关闭导致
  155.  
  156. 5.7.17安装:
  157. shell> groupadd mysql
  158. shell> useradd -r -g mysql -s /bin/false mysql
  159. shell> cd /usr/local
  160. shell> tar zxvf /path/to/mysql-VERSION-OS.tar.gz
  161. shell> ln -s full-path-to-mysql-VERSION-OS mysql
  162. shell> cd mysql
  163. shell> mkdir mysql-files
  164. shell> chmod 750 mysql-files
  165. shell> chown -R mysql .
  166. shell> chgrp -R mysql .
  167. shell> bin/mysql_install_db --user=mysql # MySQL 5.7.5
  168. shell> bin/mysqld --initialize --user=mysql # MySQL 5.7.6 and up
  169. shell> bin/mysql_ssl_rsa_setup # MySQL 5.7.6 and up
  170. shell> chown -R root .
  171. shell> chown -R mysql data mysql-files
  172. shell> bin/mysqld_safe --user=mysql &
  173. # Next command is optional
  174. shell> cp support-files/mysql.server /etc/init.d/mysql.server

源码包安装 5.6.25

  1. 1. 编译安装
  2. [root@mysql1 ~]# yum -y install ncurses ncurses-devel openssl-devel bison gcc gcc-c++ make
  3.  
  4. cmake:
  5.  
  6. mysql:
  7. [root@mysql1 ~]# groupadd mysql
  8. [root@mysql1 ~]# useradd -r -g mysql -s /bin/false mysql
  9. [root@mysql1 ~]# tar xvf mysql-5.7.17.tar.gz
  10. [root@mysql1 ~]# cd mysql-5.7.17
  11. [root@mysql-5.7.17 ~]# cmake . \
  12. -DWITH_BOOST=boost/boost_1_59_0/ \
  13. -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
  14. -DSYSCONFDIR=/etc \
  15. -DMYSQL_DATADIR=/usr/local/mysql/data \
  16. -DINSTALL_MANDIR=/usr/share/man \
  17. -DMYSQL_TCP_PORT=3306 \
  18. -DMYSQL_UNIX_ADDR=/tmp/mysql.sock \
  19. -DDEFAULT_CHARSET=utf8 \
  20. -DEXTRA_CHARSETS=all \
  21. -DDEFAULT_COLLATION=utf8_general_ci \
  22. -DWITH_READLINE=1 \
  23. -DWITH_SSL=system \
  24. -DWITH_EMBEDDED_SERVER=1 \
  25. -DENABLED_LOCAL_INFILE=1 \
  26. -DWITH_INNOBASE_STORAGE_ENGINE=1
  27.  
  28. [root@mysql1 ~]# make
  29. [root@mysql1 ~]# make install
  30.  
  31. 2. 初始化
  32. [root@mysql1 local]# cd mysql
  33. [root@mysql1 mysql]# chown -R mysql .
  34. [root@mysql1 mysql]# chgrp -R mysql .
  35. [root@mysql1 mysql]# bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
  36. [root@mysql1 mysql]# bin/mysql_ssl_rsa_setup
  37. [root@mysql1 mysql]# chown -R root .
  38. [root@mysql1 mysql]# chown -R mysql data mysql-files
  39. [root@mysql1 mysql]# \cp -rf support-files/my-default.cnf /etc/my.cnf
  40. [root@mysql1 mysql]# bin/mysqld_safe --user=mysql &
  41. [root@mysql1 mysql]# echo "export PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile
  42. [root@mysql1 mysql]# source /etc/profile
  43. [root@mysql1 mysql]# mysql -uroot -p'xxxx'
  44. mysql> alter user root@'localhost' identified by 'tianyun';

源码包安装 5.7.17

  1. MySQL5.6.31源码安装
  2. 下载链接:https://pan.baidu.com/s/1yPGylgq-BbiGwZr-QN4ztw 密码:18dc
  3.  
  4. 安装前的准备:
  5. 创建用户:
  6. [root@Admin ~]# groupadd mysql && useradd mysql -g mysql -s /bin/false
  7.  
  8. # 创建数据目录:
  9. [root@Admin ~]# mkdir -p /data/DB
  10.  
  11. # 安装必备软件:
  12. [root@Admin ~]# yum install unzip cmake ncurses-devel gcc gcc-c++ -y
  13.  
  14. # 安装mysql
  15. [root@Admin ~]# unzip mysql-5.6.31.zip && cd mysql-5.6.31
  16.  
  17. [root@Admin mysql-5.6.31]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/var/ -DWITH_DEBUG=0 -DEXTRA_CHARSETS=latin1,gb2312,big5,utf8,GBK -DEXTRA_CHARSETS=all -DWITH_INNOBASE_STORAGE_ENGINE=1 -DENABLED_LOCAL_INFILE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1
  18.  
  19. [root@Admin mysql-5.6.31]# make && make install
  20.  
  21. [root@Admin mysql-5.6.31]# cp support-files/mysql.server /etc/init.d/mysqld
  22.  
  23. # 编写配置文件
  24. [root@Admin mysql-5.6.31]# vim /etc/my.cnf
  25. [client]
  26. socket = /var/lib/mysql/mysql.sock
  27. default-character-set=utf8
  28.  
  29. [mysqld]
  30. port=3306
  31. lower_case_table_names=1 #大小写区分表明
  32. thread_concurrency=64 #通过比较 Connections 和 Threads_created 状态的变量
  33. slow_query_log=1
  34. slow_query_log_file=/data/mysqldata/slowquery.log #为MySQL慢查询日志存放的位置
  35. long_query_time=1 #2表示查询超过两秒才记录
  36. character-set-server=utf8
  37. explicit_defaults_for_timestamp #开查询缓存
  38.  
  39. socket=/var/lib/mysql/mysql.sock
  40. user=mysql
  41. # Disabling symbolic-links is recommended to prevent assorted security risks
  42. symbolic-links=0
  43. innodb_buffer_pool_size=50M
  44. innodb_additional_mem_pool=16M
  45. log-bin=mysql-bin
  46. datadir=/data/DB
  47.  
  48. log-bin-trust-function-creators=1
  49.  
  50. lower_case_table_names=1
  51. skip-external-locking
  52. key_buffer_size = 16M
  53. max_allowed_packet = 1M
  54. table_open_cache = 64
  55. sort_buffer_size = 512K
  56. net_buffer_length = 8K
  57. read_buffer_size = 256K
  58. read_rnd_buffer_size = 512K
  59. myisam_sort_buffer_size = 8M
  60. binlog_format=mixed
  61.  
  62. server-id = 1
  63.  
  64. [mysqld_safe]
  65. log-error=/var/log/mysqld.log
  66. pid-file=/var/run/mysqld/mysqld.pid
  67.  
  68. # 配置,初始化
  69. [root@Admin mysql-5.6.31]# chmod +x scripts/mysql_install_db && chmod +x /etc/init.d/mysqld
  70.  
  71. [root@Admin mysql-5.6.31]# scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/data/DB/
  72.  
  73. [root@Admin mysql-5.6.31]# chkconfig --add mysqld && chkconfig --level 35 mysqld on
  74.  
  75. [root@Admin mysql-5.6.31]# cp /usr/local/mysql/bin/mysql /usr/bin/ && cp /usr/local/mysql/bin/mysqldump /usr/bin/ && cp /usr/local/mysql/bin/mysqladmin /usr/bin/
  76.  
  77. # 启动并进入
  78. [root@Admin mysql-5.6.31]# service mysqld restart
  79. MySQL server PID file could not be found! [失败]
  80. Starting MySQL. [确定]
  81. [root@Admin mysql-5.6.31]# mysql
  82. Welcome to the MySQL monitor. Commands end with ; or \g.
  83. Your MySQL connection id is 1
  84. Server version: 5.6.31-log Source distribution
  85.  
  86. Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
  87.  
  88. Oracle is a registered trademark of Oracle Corporation and/or its
  89. affiliates. Other names may be trademarks of their respective
  90. owners.
  91.  
  92. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  93.  
  94. mysql>

源码包安装 5.6.31

MySQL 后续配置

密码设置

  1. 1》密码设置 新建立的数据库默认管理员帐号是没有密码,任何人都可以连接
  2. 修改密码三种方法:
  3. 第一种:
  4. # mysqladmin -u root password "123" --把root用户登录密码改为123
  5. # mysqladmin -u root password 'newpasswd' -p123 --有密码后,再使用这个命令改密码,就需要原密码
  6.  
  7. 第二种:
  8. 使用sql语句在数据库内部直接修改用户密码表,password()是一个密码加密函数
  9. mysql> update mysql.user set password=password("") where user="root" and host="localhost";
  10. 或者
  11. mysql> use mysql;
  12. mysql> update user set password=password(123) where user='root' and host='localhost';
  13. mysql> flush privileges; --修改过密码后都要记得刷新权限表
  14.  
  15. 第三种:
  16. mysql> set password for 'root'@'localhost'=password(''); --使用此操作语句也可以修改密码,修改后不需要刷新权限表

忘记密码

  1. # 忘记密码怎么办?
  2. 方法1
  3. 修改配置文件,在配置文件里面添加跳过授权表
  4. skip-grant-tables
  5.  
  6. 方法2
  7. 通过mysqld_safe 命令启动传递参数
  8. --skip-grant-tables

Windows 下安装MySQL

https://www.cnblogs.com/yanjieli/p/9778796.html

数据库MySQL——安装的更多相关文章

  1. 数据库 MySQL安装图解

    MySQL安装图解 一.MYSQL的安装 1.打开下载的mysql安装文件,双击运行mysql-5.5.40-win32.msi. 2.选择安装类型,有"Typical(默认)". ...

  2. 数据库-MYSQL安装配置和删除

    * 课程回顾: * 完成注册和登陆的功能. * 准备的工作 * 技术.开源jar包 * 开发的功能使用MVC模式 * C:控制层(接收请求和从客户端发送过来的参数) * 接收参数(request对象) ...

  3. 数据库-mysql安装

    MySQL 安装 所有平台的Mysql下载地址为: MySQL 下载. 挑选你需要的 MySQL Community Server 版本及对应的平台. Linux/UNIX上安装Mysql Linux ...

  4. Linux 数据库MySql 安装配置教程!

    本文价绍Linux 相关mysql 安装和配置以及基本连接测试 1官网下载安装mysql-server # wget http://dev.mysql.com/get/mysql-community- ...

  5. 数据库MySQL安装和校验

    1.安装MySQL 双击已经下载的安装包: Typical:典型安装,第一次安装建议选择该类安装 Custom:自定义安装,在对数据库熟悉后,知道自己需要哪些组件时,可以选择该类安装(这里选择的是自定 ...

  6. ubuntu 16.04 数据库mysql安装与管理

    1.安装mysql的客户端与服务器端 $>sudo apt-get install mysql-server mysql-client 2.管理服务 1.启动 $>sudo service ...

  7. 安装关系型数据库MySQL 安装大数据处理框架Hadoop

    作业要求来自:https://edu.cnblogs.com/campus/gzcc/GZCC-16SE2/homework/3161 1.Hadoop的介绍 Hadoop最早起源于Nutch.Nut ...

  8. 【大数据】安装关系型数据库MySQL安装大数据处理框架Hadoop

    作业来源于:https://edu.cnblogs.com/campus/gzcc/GZCC-16SE2/homework/3161 1. 简述Hadoop平台的起源.发展历史与应用现状. 列举发展过 ...

  9. 【大数据应用技术】作业九|安装关系型数据库MySQL 安装大数据处理框架Hadoop

    本次作业的要求来自:https://edu.cnblogs.com/campus/gzcc/GZCC-16SE2/homework/3161 1.安装MySql 按ctrl+alt+t打开终端窗口,安 ...

随机推荐

  1. c#调用word文件

    大家好!我叫蓝颜,我是一名大专生.这是我第一次接触博客园,以后也会一直在. 在学校期间,参加技能大赛(物联网),接触到的C#.之后学校教务处要一个调课软件, 于是我就小试牛刀试了试.当然了,这也是我第 ...

  2. MySQL分组查询与连接查询

    一,分组查询 使用ORDER BY子句将表中的数据分成若干组(还是按行显示) 语法: SELECT 字段名[,聚集函数] FROM 表名 [WHERE子句] GROUP BY 要分组的字段名 [ORD ...

  3. 一看就能学会的H5视频推流方案

    本文由云+社区发表 作者:周超 导语 随着直播平台爆发式增长,直播平台从 PC 端转战移动端,紧跟着直播的潮流,自己学习实现了一套简单的 H5 视频推流的解决方案,下面就给小伙伴们分享一下自己学习过程 ...

  4. [目录]C#学习笔记

    C#是微软.NET平台下最重要的编程语言,它与C.C++不同,C#编写的源程序是托管在.NET平台下的.C#源程序经C#编译器编译成中间语言(IL,Intermediate Language),再经C ...

  5. 服务器四:多进程epoll

    #include <fcntl.h> #include <sys/socket.h> #include <netinet/in.h> #include <ar ...

  6. 客户端传值里面包含URL特殊字符的应对方法

    URL传递值的时候参数里面含有%2f等URL转义问题可通过URLDecoder.decode(字符串,“utf-8”);的方法去转义为"/". 此外:URLEncoder是将字符串 ...

  7. 查看SQL Server服务运行帐户和SQL Server的所有注册表项

    查看SQL Server服务运行帐户和SQL Server的所有注册表项 SELECT * FROM sys.dm_server_registry SELECT * FROM sys.dm_serve ...

  8. python3 购物车 增改查终极版~

    还是先来条NLP再说,快没了,以后想抄还没有... 十一,没有挫败,只有回应讯息 “挫败”只是指出过去的做法得不到预期的效果,是给我们需要改变的信号. “挫败”只是在事情画上句号时才能用上,欲想事情解 ...

  9. Linux学习-汇总

    1.基础linux学习 Linux-基础学习(一)-基本命令 Linux-基础学习(二)-基本部署 Linux-基础学习(三)-Nginx学习 Linux-基础学习(四)-部署图书管理系统项目 Lin ...

  10. vue启动时候报错

    使用vue时,在已经安装模块完毕的情况下,依旧会报错,如: Module build failed: Error: %1 is not a valid Win32 application. 这个时候只 ...