MySql5.7免安装版配置过程(ubuntu16.04)

MySql5.7免安装版配置过程(ubuntu16.04)

原创
2017年02月07日 16:58:24

        <ul class="article_tags clearfix csdn-tracking-statistics" data-mod="popu_377" style="display: none;">
<li class="tit">标签:</li>

            <!--          [endarticletags]-->
</ul>
<ul class="right_bar">
<li><button class="btn-noborder"><i class="icon iconfont icon-read"></i><span class="txt">1001</span></button></li>
<li class="edit" style="display: none;">
<a class="btn-noborder" href="http://write.blog.csdn.net/postedit/54911665">
<i class="icon iconfont icon-bianji"></i><span class="txt">编辑</span>
</a>
</li>
<li class="del" style="display: none;">
<a class="btn-noborder" onclick="javascript:deleteArticle(fileName);return false;">
<i class="icon iconfont icon-shanchu"></i><span class="txt">删除</span>
</a>
</li>
</ul>
</div>
<div id="article_content" class="article_content csdn-tracking-statistics" data-mod="popu_519" data-dsm="post" style="overflow: hidden;">

一、安装环境:

操作系统:ubuntu16.04

数据库:mysql-5.7.17-linux-glibc2.5-x86_64 (免安装版)

二、解压

tar -xzvf mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz

mv mysql-5.7.17-linux-glibc2.5-x86_64   /usr/local/mysql

三、增加用户和组

groupadd mysql;

useradd -g mysql mysql;

四、创建目录及目录权限:

mkdir /mysql /mysql/data /mysql/log

  修改目录权限

   chown -R mysql:mysql /usr/local/mysql /mysql

五、在/etc目录下创建文件:my.cnf

  直接使用 vi my.cnf创建

  1. [client]
  2. port = 3306
  3. socket = /tmp/mysql.sock
  4. [mysqld]
  5. server_id=10
  6. port = 3306
  7. user = mysql
  8. socket = /tmp/mysql.sock
  9. basedir = /usr/local/mysql
  10. datadir = /mysql/data
  11. pid-file = /mysql/data/mysql.pid
  12. max_connections = 1000
  13. max_connect_errors = 1000
  14. table_open_cache = 1024
  15. max_allowed_packet = 128M
  16. open_files_limit = 65535
  17. #####====================================[innodb]==============================
  18. innodb_buffer_pool_size = 1024M
  19. innodb_file_per_table = 1
  20. innodb_write_io_threads = 4
  21. innodb_read_io_threads = 4
  22. innodb_purge_threads = 2
  23. innodb_flush_log_at_trx_commit = 1
  24. innodb_log_file_size = 512M
  25. innodb_log_files_in_group = 2
  26. innodb_log_buffer_size = 16M
  27. innodb_max_dirty_pages_pct = 80
  28. innodb_lock_wait_timeout = 30
  29. innodb_data_file_path=ibdata1:1024M:autoextend
  30. #####====================================[log]==============================
  31. log_error = /mysql/log/mysql-error.log
  32. slow_query_log = 1
  33. long_query_time = 1
  34. slow_query_log_file = /mysql/log/mysql-slow.log
  35. sql_mode=ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
[client]
port = 3306
socket = /tmp/mysql.sock [mysqld]

server_id=10

port = 3306

user = mysql

socket = /tmp/mysql.sock

basedir = /usr/local/mysql

datadir = /mysql/data

pid-file = /mysql/data/mysql.pid

max_connections = 1000

max_connect_errors = 1000

table_open_cache = 1024

max_allowed_packet = 128M

open_files_limit = 65535
======[innodb]
innodb_buffer_pool_size = 1024M

innodb_file_per_table = 1

innodb_write_io_threads = 4

innodb_read_io_threads = 4

innodb_purge_threads = 2

innodb_flush_log_at_trx_commit = 1

innodb_log_file_size = 512M

innodb_log_files_in_group = 2

innodb_log_buffer_size = 16M

innodb_max_dirty_pages_pct = 80

innodb_lock_wait_timeout = 30

innodb_data_file_path=ibdata1:1024M:autoextend
======[log]
log_error = /mysql/log/mysql-error.log

slow_query_log = 1

long_query_time = 1

slow_query_log_file = /mysql/log/mysql-slow.log sql_mode=ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

六、初始化数据库及配置

注意:5.7.6之后的版本初始化数据库不再使用mysql_install_db

  bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/mysql/data  --innodb_undo_tablespaces=3 --explicit_defaults_for_timestamp

如果配置了my.cnf的log_error,那么初始密码在log_error文件中,否则会打印出来。

  bin/mysql_ssl_rsa_setup --datadir=/mysql/data

  修改目录权限

 chown -R mysql:mysql /usr/local/mysql /mysql

  配置启动文件

 cp support-files/mysql.server /etc/init.d/mysql

  配置环境变量

  mysql_home=/usr/local/mysql
PATH=$PATH:$mysql_home/bin

七、配置数据库密码及远程访问:

使用初始化密码进行登录:

密码存储在日志文件中:sudo vi mysql-error.log

mysql -u root -p *******

 初次使用,设置root密码:
SET PASSWORD=PASSWORD('root');

然后才可以使用和操作数据库进行修改:

   update mysql.user set authentication_string=password('root') where user='root';

修改远程访问权限

mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root_password' WITH GRANT OPTION;

       mysql> FLUSH PRIVILEGES ;

八、ubuntu下增加mysql到系统默认启动

  sudo update-rc.d mysql defaults
上一篇:MySQL5.7免安装版配置图文教程


下一篇:STORJ 有实际应用