大橙子网站建设,新征程启航

为企业提供网站建设、域名注册、服务器等服务

mysql5.6单实例安装(二进制)

1.下载二进制安装包
MySQL-5.6.39-linux-glibc2.12-x86_64.tar.gz
tar -xvf mysql-5.6.39-linux-glibc2.12-x86_64.tar.gz

2.拷贝安装包和配置文件(如果没有特殊情况,将安装包解压放置在该目录)
cp -rf mysql /usr/local/mysql
cp -rf my5.6.cnf /etc/my.cnf

3.创建mysql用户
useradd mysql

4.添加数据目录
mkdir -p /home/mysql3306/mysql3306
mkdir -p /home/mysql3306/logs

5.修改目录权限
chown mysql:mysql -R /home/mysql3306

6.修改配置文件
socket          = /tmp/mysql.sock(socket文件存放位置)
datadir         = /home/mysql3306/mysql3306(数据文件存放目录)
server-id               = 12013306(设置serverid 命名规则:ip后两位+端口号)
port            = 3306(启动端口)
innodb_buffer_pool_size         = 1024M(innodb buffer pool大小)
*如果是核心节点单实例 配置成系统总内存的75%左右,如果不是核心节点则按照具体业务压力来设置

7.初始化数据库(确认2个OK)

点击(此处)折叠或打开

10年积累的网站建设、成都网站设计经验,可以快速应对客户对网站的新想法和需求。提供各种问题对应的解决方案。让选择我们的客户得到更好、更有力的网络服务。我虽然不认识你,你也不认识我。但先网站制作后付款的网站建设流程,更有泾源免费网站建设让你可以放心的选择与我们合作。

  1. # /usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --defaults-file=/etc/my.cnf --datadir=/home/mysql3306/mysql3306 --user=mysql
  2. Installing MySQL system tables...2018-03-10 19:33:26 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
  3. 2018-03-10 19:33:26 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
  4. 2018-03-10 19:33:26 0 [Note] /usr/local/mysql/bin/mysqld (mysqld 5.6.39-log) starting as process 2041 ...
  5. OK
  6. Filling help tables...2018-03-10 19:33:37 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
  7. 2018-03-10 19:33:37 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
  8. 2018-03-10 19:33:37 0 [Note] /usr/local/mysql/bin/mysqld (mysqld 5.6.39-log) starting as process 2063 ...
  9. OK
  10. To start mysqld at boot time you have to copy
  11. support-files/mysql.server to the right place for your system
  12. PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
  13. To do so, start the server, then issue the following commands:
  14. /usr/local/mysql/bin/mysqladmin -u root password 'new-password'
  15. /usr/local/mysql/bin/mysqladmin -u root -h mysql5.6 password 'new-password'
  16. Alternatively you can run:
  17. /usr/local/mysql/bin/mysql_secure_installation
  18. which will also give you the option of removing the test
  19. databases and anonymous user created by default. This is
  20. strongly recommended for production servers.
  21. See the manual for more instructions.
  22. You can start the MySQL daemon with:
  23. cd . ; /usr/local/mysql/bin/mysqld_safe &
  24. You can test the MySQL daemon with mysql-test-run.pl
  25. cd mysql-test ; perl mysql-test-run.pl
  26. Please report any problems at http://bugs.mysql.com/
  27. The latest information about MySQL is available on the web at
  28. http://www.mysql.com
  29. Support MySQL by buying support/licenses at http://shop.mysql.com
  30. New default config file was created as /usr/local/mysql/my.cnf and
  31. will be used by default by the server when you start it.
  32. You may edit this file to change server settings
  33. WARNING: Default config file /etc/my.cnf exists on the system
  34. This file will be read by default by the MySQL server
  35. If you do not want to use this, either remove it, or use the
  36. --defaults-file argument to mysqld_safe when starting the server
数据目录下文件

点击(此处)折叠或打开

  1. [root@mysql5 mysql3306]# ll
  2. total 1574132
  3. -rw-rw----. 1 mysql mysql 1073741824 Mar 10 19:33 ibdata1
  4. -rw-rw----. 1 mysql mysql 268435456 Mar 10 19:33 ib_logfile0
  5. -rw-rw----. 1 mysql mysql 268435456 Mar 10 19:33 ib_logfile1
  6. drwx------. 2 mysql mysql 4096 Mar 10 19:33 mysql
  7. -rw-rw----. 1 mysql mysql 65405 Mar 10 19:33 mysql-bin.000001
  8. -rw-rw----. 1 mysql mysql 1206067 Mar 10 19:33 mysql-bin.000002
  9. -rw-rw----. 1 mysql mysql 38 Mar 10 19:33 mysql-bin.index
  10. drwx------. 2 mysql mysql 4096 Mar 10 19:33 performance_schema
  11. drwx------. 2 mysql mysql 4096 Mar 10 19:33 test

8.启动mysql5.6

点击(此处)折叠或打开

  1. # /usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf --user=mysql &
  2. [1] 2108
  3. [root@mysql5 mysql3306]# 180310 19:40:55 mysqld_safe Logging to '/home/mysql3306/logs/mysql-error.log'.
  4. 180310 19:40:55 mysqld_safe Starting mysqld daemon with databases from /home/mysql3306/mysql3306

点击(此处)折叠或打开

  1. # ps -ef |grep mysql
  2. avahi 1312 1 0 18:36 ? 00:00:00 avahi-daemon: running [mysql5.local]
  3. root 2108 1821 0 19:40 pts/0 00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf --user=mysql
  4. mysql 2979 2108 7 19:40 pts/0 00:00:06 /usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql --datadir=/home/mysql3306/mysql3306 --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/home/mysql3306/logs/mysql-error.log --open-files-limit=65535 --pid-file=/home/mysql3306/mysql.pid --socket=/tmp/mysql.sock --port=3306
  5. root 3004 1821 0 19:42 pts/0 00:00:00 grep mysql

9.进入mysql5.6

点击(此处)折叠或打开

  1. # /usr/local/mysql/bin/mysql -S /tmp/mysql.sock
  2. Welcome to the MySQL monitor. Commands end with ; or \g.
  3. Your MySQL connection id is 1
  4. Server version: 5.6.39-log MySQL Community Server (GPL)
  5. Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
  6. Oracle is a registered trademark of Oracle Corporation and/or its
  7. affiliates. Other names may be trademarks of their respective
  8. owners.
  9. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  10. mysql> show databases;
  11. +--------------------+
  12. | Database |
  13. +--------------------+
  14. | information_schema |
  15. | mysql |
  16. | performance_schema |
  17. | test |
  18. +--------------------+
  19. 4 rows in set (0.05 sec)

10.权限调整

点击(此处)折叠或打开

  1. mysql> select user,host,password from mysql.user;
  2. ERROR 2006 (HY000): MySQL server has gone away
  3. No connection. Trying to reconnect...
  4. Connection id: 2
  5. Current database: *** NONE ***
  6. +------+-----------+----------+
  7. | user | host | password |
  8. +------+-----------+----------+
  9. | root | localhost | |
  10. | root | mysql5.6 | |
  11. | root | 127.0.0.1 | |
  12. | root | ::1 | |
  13. | | localhost | |
  14. | | mysql5.6 | |
  15. +------+-----------+----------+
  16. 6 rows in set (0.08 sec)
删除空用户
mysql> delete from mysql.user where user='';
Query OK, 2 rows affected (0.06 sec)
mysql> delete from mysql.user where host in ('::1','tomato02');
Query OK, 1 row affected (0.02 sec)

使生效
mysql> flush privileges;
Query OK, 0 rows affected (0.02 sec)

赋权限
mysql> grant all on *.* to root@'localhost' identified by 'root';
Query OK, 0 rows affected (0.04 sec)
mysql> grant all on *.* to root@'%' identified by 'root';
Query OK, 0 rows affected (0.01 sec)

-all 所有权限
-*.* 所有权限的(所有库的所有表)
-root@'localhost'  用户@网段  localhost通过sock访问数据库,通过本地方式访问数据库
-root@'%'           通过TCP/IP协议来访问数据库,TCP/IP可以远程访问
-identified by 'root';   密码root

使用密码登录数据库
# /usr/local/mysql/bin/mysql -S /tmp/mysql.sock -p
Enter password:

查看帮助

点击(此处)折叠或打开

  1. # /usr/local/mysql/bin/mysql --help
  2. /usr/local/mysql/bin/mysql Ver 14.14 Distrib 5.6.39, for linux-glibc2.12 (x86_64) using EditLine wrapper
  3. Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
  4. Oracle is a registered trademark of Oracle Corporation and/or its
  5. affiliates. Other names may be trademarks of their respective
  6. owners.
  7. Usage: /usr/local/mysql/bin/mysql [OPTIONS] [database]
  8. -?, --help Display this help and exit.
  9. -I, --help Synonym for -?
  10. --auto-rehash Enable automatic rehashing. One doesn't need to use
  11. 'rehash' to get table and field completion, but startup
  12. and reconnecting may take a longer time. Disable with
  13. --disable-auto-rehash.
  14. (Defaults to on; use --skip-auto-rehash to disable.)
  15. -A, --no-auto-rehash
  16. No automatic rehashing. One has to use 'rehash' to get
  17. table and field completion. This gives a quicker start of
  18. mysql and disables rehashing on reconnect.
  19. --auto-vertical-output
  20. Automatically switch to vertical output mode if the
  21. result is wider than the terminal width.
  22. -B, --batch Don't use history file. Disable interactive behavior.
  23. (Enables --silent.)
  24. --bind-address=name IP address to bind to.
  25. -b, --binary-as-hex Print binary data as hex
  26. --character-sets-dir=name
  27. Directory for character set files.
  28. --column-type-info Display column type information.
  29. -c, --comments Preserve comments. Send comments to the server. The
  30. default is --skip-comments (discard comments), enable
  31. with --comments.
  32. -C, --compress Use compression in server/client protocol.
  33. -#, --debug[=#] This is a non-debug version. Catch this and exit.
  34. --debug-check Check memory and open file usage at exit.
  35. -T, --debug-info Print some debug info at exit.
  36. -D, --database=name Database to use.
  37. --default-character-set=name
  38. Set the default character set.
  39. --delimiter=name Delimiter to be used.
  40. --enable-cleartext-plugin
  41. Enable/disable the clear text authentication plugin.
  42. -e, --execute=name Execute command and quit. (Disables --force and history
  43. file.)
  44. -E, --vertical Print the output of a query (rows) vertically.
  45. -f, --force Continue even if we get an SQL error.
  46. -G, --named-commands
  47. Enable named commands. Named commands mean this program's
  48. internal commands; see mysql> help . When enabled, the
  49. named commands can be used from any line of the query,
  50. otherwise only from the first line, before an enter.
  51. Disable with --disable-named-commands. This option is
  52. disabled by default.
  53. -i, --ignore-spaces Ignore space after function names.
  54. --init-command=name SQL Command to execute when connecting to MySQL server.
  55. Will automatically be re-executed when reconnecting.
  56. --local-infile Enable/disable LOAD DATA LOCAL INFILE.
  57. -b, --no-beep Turn off beep on error.
  58. -h, --host=name Connect to host.
  59. -H, --html Produce HTML output.
  60. -X, --xml Produce XML output.
  61. --line-numbers Write line numbers for errors.
  62. (Defaults to on; use --skip-line-numbers to disable.)
  63. -L, --skip-line-numbers
  64. Don't write line number for errors.
  65. -n, --unbuffered Flush buffer after each query.
  66. --column-names Write column names in results.
  67. (Defaults to on; use --skip-column-names to disable.)
  68. -N, --skip-column-names
  69. Don't write column names in results.
  70. --sigint-ignore Ignore SIGINT (CTRL-C).
  71. -o, --one-database Ignore statements except those that occur while the
  72. default database is the one named at the command line.
  73. --pager[=name] Pager to use to display results. If you don't supply an
  74. option, the default pager is taken from your ENV variable
  75. PAGER. Valid pagers are less, more, cat [> filename],
  76. etc. See interactive help (\h) also. This option does not
  77. work in batch mode. Disable with --disable-pager. This
  78. option is disabled by default.
  79. -p, --password[=name]
  80. Password to use when connecting to server. If password is
  81. not given it's asked from the tty.
  82. -P, --port=# Port number to use for connection or 0 for default to, in
  83. order of preference, my.cnf, $MYSQL_TCP_PORT,
  84. /etc/services, built-in default (3306).
  85. --prompt=name Set the mysql prompt to this value.
  86. --protocol=name The protocol to use for connection (tcp, socket, pipe,
  87. memory).
  88. -q, --quick Don't cache result, print it row by row. This may slow
  89. down the server if the output is suspended. Doesn't use
  90. history file.
  91. -r, --raw Write fields without conversion. Used with --batch.
  92. --reconnect Reconnect if the connection is lost. Disable with
  93. --disable-reconnect. This option is enabled by default.
  94. (Defaults to on; use --skip-reconnect to disable.)
  95. -s, --silent Be more silent. Print results with a tab as separator,
  96. each row on new line.
  97. -S, --socket=name The socket file to use for connection.
  98. --ssl Enable SSL for connection (automatically enabled with
  99. other flags).
  100. --ssl-ca=name CA file in PEM format (check OpenSSL docs, implies
  101. --ssl).
  102. --ssl-capath=name CA directory (check OpenSSL docs, implies --ssl).
  103. --ssl-cert=name X509 cert in PEM format (implies --ssl).
  104. --ssl-cipher=name SSL cipher to use (implies --ssl).
  105. --ssl-key=name X509 key in PEM format (implies --ssl).
  106. --ssl-crl=name Certificate revocation list (implies --ssl).
  107. --ssl-crlpath=name Certificate revocation list path (implies --ssl).
  108. --ssl-verify-server-cert
  109. Verify server's "Common Name" in its cert against
  110. hostname used when connecting. This option is disabled by
  111. default.
  112. --ssl-mode=name SSL connection mode.
  113. -t, --table Output in table format.
  114. --tee=name Append everything into outfile. See interactive help (\h)
  115. also. Does not work in batch mode. Disable with
  116. --disable-tee. This option is disabled by default.
  117. -u, --user=name User for login if not current user.
  118. -U, --safe-updates Only allow UPDATE and DELETE that uses keys.
  119. -U, --i-am-a-dummy Synonym for option --safe-updates, -U.
  120. -v, --verbose Write more. (-v -v -v gives the table output format).
  121. -V, --version Output version information and exit.
  122. -w, --wait Wait and retry if connection is down.
  123. --connect-timeout=# Number of seconds before connection timeout.
  124. --max-allowed-packet=#
  125. The maximum packet length to send to or receive from
  126. server.
  127. --net-buffer-length=#
  128. The buffer size for TCP/IP and socket communication.
  129. --select-limit=# Automatic limit for SELECT when using --safe-updates.
  130. --max-join-size=# Automatic limit for rows in a join when using
  131. --safe-updates.
  132. --secure-auth Refuse client connecting to server if it uses old
  133. (pre-4.1.1) protocol.
  134. (Defaults to on; use --skip-secure-auth to disable.)
  135. --server-arg=name Send embedded server this as a parameter.
  136. --show-warnings Show warnings after every statement.
  137. --plugin-dir=name Directory for client-side plugins.
  138. --default-auth=name Default authentication client-side plugin to use.
  139. --histignore=name A colon-separated list of patterns to keep statements
  140. from getting logged into mysql history.
  141. --binary-mode By default, ASCII '\0' is disallowed and '\r\n' is
  142. translated to '\n'. This switch turns off both features,
  143. and also turns off parsing of all clientcommands except
  144. \C and DELIMITER, in non-interactive mode (for input
  145. piped to mysql or loaded using the 'source' command).
  146. This is necessary when processing output from mysqlbinlog
  147. that may contain blobs.
  148. --connect-expired-password
  149. Notify the server that this client is prepared to handle
  150. expired password sandbox mode.
  151. Default options are read from the following files in the given order:
  152. /etc/my.cnf /etc/mysql/my.cnf /usr/local/mysql/etc/my.cnf ~/.my.cnf
  153. The following groups are read: mysql client
  154. The following options may be given as the first argument:
  155. --print-defaults Print the program argument list and exit.
  156. --no-defaults Don't read default options from any option file,
  157. except for login file.
  158. --defaults-file=# Only read default options from the given file #.
  159. --defaults-extra-file=# Read this file after the global files are read.
  160. --defaults-group-suffix=#
  161. Also read groups with concat(group, suffix)
  162. --login-path=# Read this path from the login file.
  163. Variables (--variable-name=value)
  164. and boolean options {FALSE|TRUE} Value (after reading options)
  165. --------------------------------- ----------------------------------------
  166. auto-rehash TRUE
  167. auto-vertical-output FALSE
  168. bind-address (No default value)
  169. binary-as-hex FALSE
  170. character-sets-dir (No default value)
  171. column-type-info FALSE
  172. comments FALSE
  173. compress FALSE
  174. debug-check FALSE
  175. debug-info FALSE
  176. database (No default value)
  177. default-character-set utf8
  178. delimiter ;
  179. enable-cleartext-plugin FALSE
  180. vertical FALSE
  181. force FALSE
  182. named-commands FALSE
  183. ignore-spaces FALSE
  184. init-command (No default value)
  185. local-infile FALSE
  186. no-beep FALSE
  187. host (No default value)
  188. html FALSE
  189. xml FALSE
  190. line-numbers TRUE
  191. unbuffered FALSE
  192. column-names TRUE
  193. sigint-ignore FALSE
  194. port 3306
  195. prompt mysql>
  196. quick FALSE
  197. raw FALSE
  198. reconnect TRUE
  199. socket /tmp/mysql.sock
  200. ssl FALSE
  201. ssl-ca (No default value)
  202. ssl-capath (No default value)
  203. ssl-cert (No default value)
  204. ssl-cipher (No default value)
  205. ssl-key (No default value)
  206. ssl-crl (No default value)
  207. ssl-crlpath (No default value)
  208. ssl-verify-server-cert FALSE
  209. table FALSE
  210. user (No default value)
  211. safe-updates FALSE
  212. i-am-a-dummy FALSE
  213. connect-timeout 0
  214. max-allowed-packet 16777216
  215. net-buffer-length 16384
  216. select-limit 1000
  217. max-join-size 1000000
  218. secure-auth FALSE
  219. show-warnings FALSE
  220. plugin-dir (No default value)
  221. default-auth (No default value)
  222. histignore (No default value)
  223. binary-mode FALSE
  224. connect-expired-password FALSE

11.关闭mysql

点击(此处)折叠或打开

  1. # /usr/local/mysql/bin/mysqladmin -uroot -proot -S /tmp/mysql.sock shutdown
  2. Warning: Using a password on the command line interface can be insecure.
  3. 180310 20:36:38 mysqld_safe mysqld from pid file /home/mysql3306/mysql.pid ended
  4. [1]+ Done /usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf --user=mysql
强行关闭mysql
pkill mysql

12.mysql错误日志
/home/mysql3306/logs/mysql-error.log









名称栏目:mysql5.6单实例安装(二进制)
路径分享:http://dzwzjz.com/article/ijjehe.html
在线咨询
服务热线
服务热线:028-86922220
TOP