【MYSQL】MYSQLの環境構築

ダウンロード:https://dev.mysql.com/downloads/mysql/

手順①

手順②

mysql.iniの設定について

 [mysql]
default-character-set=utf8

[mysqld]
port=3306
basedir=D:programmysql-8.0.11-winx64
datadir=D:programmysql-8.0.11-winx64data
max_connections=200
character-set-server=utf8
default-storage-engine=INNODB

 1 [mysqld]
 2 # 设置3306端口
 3 port=3306
 4 # 设置mysql的安装目录
 5 basedir=C:Program FilesMySQL
 6 # 设置mysql数据库的数据的存放目录
 7 datadir=E:databaseMySQLData
 8 # 允许最大连接数
 9 max_connections=200
10 # 允许连接失败的次数。这是为了防止有人从该主机试图攻击数据库系统
11 max_connect_errors=10
12 # 服务端使用的字符集默认为UTF8
13 character-set-server=utf8
14 # 创建新表时将使用的默认存储引擎
15 default-storage-engine=INNODB
16 # 默认使用“mysql_native_password”插件认证
17 default_authentication_plugin=mysql_native_password
18 [mysql]
19 # 设置mysql客户端默认字符集
20 default-character-set=utf8
21 [client]
22 # 设置mysql客户端连接服务端时默认使用的端口
23 port=3306
24 default-character-set=utf8
my.ini

参考ファイル:

 1 # Example MySQL config file for small systems.
 2 #
 3 # This is for a system with little memory (<= 64M) where MySQL is only used
 4 # from time to time and it's important that the mysqld daemon
 5 # doesn't use much resources.
 6 #
 7 # MySQL programs look for option files in a set of
 8 # locations which depend on the deployment platform.
 9 # You can copy this option file to one of those
10 # locations. For information about these locations, see:
11 # http://dev.mysql.com/doc/mysql/en/option-files.html
12 #
13 # In this file, you can use all long options that a program supports.
14 # If you want to know which options a program supports, run the program
15 # with the "--help" option.
16 
17 # The following options will be passed to all MySQL clients
18 [client]
19 #password    = your_password
20 port        = 3306
21 socket        = /tmp/mysql.sock
22 
23 # Here follows entries for some specific programs
24 
25 # The MySQL server
26 [mysqld]
27 port        = 3306
28 socket        = /tmp/mysql.sock
29 skip-external-locking
30 key_buffer_size = 16K
31 max_allowed_packet = 1M
32 table_open_cache = 4
33 sort_buffer_size = 64K
34 read_buffer_size = 256K
35 read_rnd_buffer_size = 256K
36 net_buffer_length = 2K
37 thread_stack = 128K
38 
39 # Don't listen on a TCP/IP port at all. This can be a security enhancement,
40 # if all processes that need to connect to mysqld run on the same host.
41 # All interaction with mysqld must be made via Unix sockets or named pipes.
42 # Note that using this option without enabling named pipes on Windows
43 # (using the "enable-named-pipe" option) will render mysqld useless!
44 # 
45 #skip-networking
46 server-id    = 1
47 
48 # Uncomment the following if you want to log updates
49 #log-bin=mysql-bin
50 
51 # binary logging format - mixed recommended
52 #binlog_format=mixed
53 
54 # Causes updates to non-transactional engines using statement format to be
55 # written directly to binary log. Before using this option make sure that
56 # there are no dependencies between transactional and non-transactional
57 # tables such as in the statement INSERT INTO t_myisam SELECT * FROM
58 # t_innodb; otherwise, slaves may diverge from the master.
59 #binlog_direct_non_transactional_updates=TRUE
60 
61 # Uncomment the following if you are using InnoDB tables
62 #innodb_data_home_dir = C:\mysql\data\
63 #innodb_data_file_path = ibdata1:10M:autoextend
64 #innodb_log_group_home_dir = C:\mysql\data\
65 # You can set .._buffer_pool_size up to 50 - 80 %
66 # of RAM but beware of setting memory usage too high
67 #innodb_buffer_pool_size = 16M
68 #innodb_additional_mem_pool_size = 2M
69 # Set .._log_file_size to 25 % of buffer pool size
70 #innodb_log_file_size = 5M
71 #innodb_log_buffer_size = 8M
72 #innodb_flush_log_at_trx_commit = 1
73 #innodb_lock_wait_timeout = 50
74 
75 [mysqldump]
76 quick
77 max_allowed_packet = 16M
78 
79 [mysql]
80 no-auto-rehash
81 # Remove the next comment character if you are not familiar with SQL
82 #safe-updates
83 
84 [myisamchk]
85 key_buffer_size = 8M
86 sort_buffer_size = 8M
87 
88 [mysqlhotcopy]
89 interactive-timeout
my-small.ini
  1 # Example MySQL config file for medium systems.
  2 #
  3 # This is for a system with little memory (32M - 64M) where MySQL plays
  4 # an important part, or systems up to 128M where MySQL is used together with
  5 # other programs (such as a web server)
  6 #
  7 # MySQL programs look for option files in a set of
  8 # locations which depend on the deployment platform.
  9 # You can copy this option file to one of those
 10 # locations. For information about these locations, see:
 11 # http://dev.mysql.com/doc/mysql/en/option-files.html
 12 #
 13 # In this file, you can use all long options that a program supports.
 14 # If you want to know which options a program supports, run the program
 15 # with the "--help" option.
 16 
 17 # The following options will be passed to all MySQL clients
 18 [client]
 19 #password    = your_password
 20 port        = 3306
 21 socket        = /tmp/mysql.sock
 22 
 23 # Here follows entries for some specific programs
 24 
 25 # The MySQL server
 26 [mysqld]
 27 port        = 3306
 28 socket        = /tmp/mysql.sock
 29 skip-external-locking
 30 key_buffer_size = 16M
 31 max_allowed_packet = 1M
 32 table_open_cache = 64
 33 sort_buffer_size = 512K
 34 net_buffer_length = 8K
 35 read_buffer_size = 256K
 36 read_rnd_buffer_size = 512K
 37 myisam_sort_buffer_size = 8M
 38 
 39 # Don't listen on a TCP/IP port at all. This can be a security enhancement,
 40 # if all processes that need to connect to mysqld run on the same host.
 41 # All interaction with mysqld must be made via Unix sockets or named pipes.
 42 # Note that using this option without enabling named pipes on Windows
 43 # (via the "enable-named-pipe" option) will render mysqld useless!
 44 # 
 45 #skip-networking
 46 
 47 # Replication Master Server (default)
 48 # binary logging is required for replication
 49 log-bin=mysql-bin
 50 
 51 # binary logging format - mixed recommended
 52 binlog_format=mixed
 53 
 54 # required unique id between 1 and 2^32 - 1
 55 # defaults to 1 if master-host is not set
 56 # but will not function as a master if omitted
 57 server-id    = 1
 58 
 59 # Replication Slave (comment out master section to use this)
 60 #
 61 # To configure this host as a replication slave, you can choose between
 62 # two methods :
 63 #
 64 # 1) Use the CHANGE MASTER TO command (fully described in our manual) -
 65 #    the syntax is:
 66 #
 67 #    CHANGE MASTER TO MASTER_HOST=<host>, MASTER_PORT=<port>,
 68 #    MASTER_USER=<user>, MASTER_PASSWORD=<password> ;
 69 #
 70 #    where you replace <host>, <user>, <password> by quoted strings and
 71 #    <port> by the master's port number (3306 by default).
 72 #
 73 #    Example:
 74 #
 75 #    CHANGE MASTER TO MASTER_HOST='125.564.12.1', MASTER_PORT=3306,
 76 #    MASTER_USER='joe', MASTER_PASSWORD='secret';
 77 #
 78 # OR
 79 #
 80 # 2) Set the variables below. However, in case you choose this method, then
 81 #    start replication for the first time (even unsuccessfully, for example
 82 #    if you mistyped the password in master-password and the slave fails to
 83 #    connect), the slave will create a master.info file, and any later
 84 #    change in this file to the variables' values below will be ignored and
 85 #    overridden by the content of the master.info file, unless you shutdown
 86 #    the slave server, delete master.info and restart the slaver server.
 87 #    For that reason, you may want to leave the lines below untouched
 88 #    (commented) and instead use CHANGE MASTER TO (see above)
 89 #
 90 # required unique id between 2 and 2^32 - 1
 91 # (and different from the master)
 92 # defaults to 2 if master-host is set
 93 # but will not function as a slave if omitted
 94 #server-id       = 2
 95 #
 96 # The replication master for this slave - required
 97 #master-host     =   <hostname>
 98 #
 99 # The username the slave will use for authentication when connecting
100 # to the master - required
101 #master-user     =   <username>
102 #
103 # The password the slave will authenticate with when connecting to
104 # the master - required
105 #master-password =   <password>
106 #
107 # The port the master is listening on.
108 # optional - defaults to 3306
109 #master-port     =  <port>
110 #
111 # binary logging - not required for slaves, but recommended
112 #log-bin=mysql-bin
113 
114 # Uncomment the following if you are using InnoDB tables
115 #innodb_data_home_dir = C:\mysql\data\
116 #innodb_data_file_path = ibdata1:10M:autoextend
117 #innodb_log_group_home_dir = C:\mysql\data\
118 # You can set .._buffer_pool_size up to 50 - 80 %
119 # of RAM but beware of setting memory usage too high
120 #innodb_buffer_pool_size = 16M
121 #innodb_additional_mem_pool_size = 2M
122 # Set .._log_file_size to 25 % of buffer pool size
123 #innodb_log_file_size = 5M
124 #innodb_log_buffer_size = 8M
125 #innodb_flush_log_at_trx_commit = 1
126 #innodb_lock_wait_timeout = 50
127 
128 [mysqldump]
129 quick
130 max_allowed_packet = 16M
131 
132 [mysql]
133 no-auto-rehash
134 # Remove the next comment character if you are not familiar with SQL
135 #safe-updates
136 
137 [myisamchk]
138 key_buffer_size = 20M
139 sort_buffer_size = 20M
140 read_buffer = 2M
141 write_buffer = 2M
142 
143 [mysqlhotcopy]
144 interactive-timeout
my-medium.ini
  1 # Example MySQL config file for large systems.
  2 #
  3 # This is for a large system with memory = 512M where the system runs mainly
  4 # MySQL.
  5 #
  6 # MySQL programs look for option files in a set of
  7 # locations which depend on the deployment platform.
  8 # You can copy this option file to one of those
  9 # locations. For information about these locations, see:
 10 # http://dev.mysql.com/doc/mysql/en/option-files.html
 11 #
 12 # In this file, you can use all long options that a program supports.
 13 # If you want to know which options a program supports, run the program
 14 # with the "--help" option.
 15 
 16 # The following options will be passed to all MySQL clients
 17 [client]
 18 #password    = your_password
 19 port        = 3306
 20 socket        = /tmp/mysql.sock
 21 
 22 # Here follows entries for some specific programs
 23 
 24 # The MySQL server
 25 [mysqld]
 26 port        = 3306
 27 socket        = /tmp/mysql.sock
 28 skip-external-locking
 29 key_buffer_size = 256M
 30 max_allowed_packet = 1M
 31 table_open_cache = 256
 32 sort_buffer_size = 1M
 33 read_buffer_size = 1M
 34 read_rnd_buffer_size = 4M
 35 myisam_sort_buffer_size = 64M
 36 thread_cache_size = 8
 37 query_cache_size= 16M
 38 # Try number of CPU's*2 for thread_concurrency
 39 thread_concurrency = 8
 40 
 41 # Don't listen on a TCP/IP port at all. This can be a security enhancement,
 42 # if all processes that need to connect to mysqld run on the same host.
 43 # All interaction with mysqld must be made via Unix sockets or named pipes.
 44 # Note that using this option without enabling named pipes on Windows
 45 # (via the "enable-named-pipe" option) will render mysqld useless!
 46 # 
 47 #skip-networking
 48 
 49 # Replication Master Server (default)
 50 # binary logging is required for replication
 51 log-bin=mysql-bin
 52 
 53 # binary logging format - mixed recommended
 54 binlog_format=mixed
 55 
 56 # required unique id between 1 and 2^32 - 1
 57 # defaults to 1 if master-host is not set
 58 # but will not function as a master if omitted
 59 server-id    = 1
 60 
 61 # Replication Slave (comment out master section to use this)
 62 #
 63 # To configure this host as a replication slave, you can choose between
 64 # two methods :
 65 #
 66 # 1) Use the CHANGE MASTER TO command (fully described in our manual) -
 67 #    the syntax is:
 68 #
 69 #    CHANGE MASTER TO MASTER_HOST=<host>, MASTER_PORT=<port>,
 70 #    MASTER_USER=<user>, MASTER_PASSWORD=<password> ;
 71 #
 72 #    where you replace <host>, <user>, <password> by quoted strings and
 73 #    <port> by the master's port number (3306 by default).
 74 #
 75 #    Example:
 76 #
 77 #    CHANGE MASTER TO MASTER_HOST='125.564.12.1', MASTER_PORT=3306,
 78 #    MASTER_USER='joe', MASTER_PASSWORD='secret';
 79 #
 80 # OR
 81 #
 82 # 2) Set the variables below. However, in case you choose this method, then
 83 #    start replication for the first time (even unsuccessfully, for example
 84 #    if you mistyped the password in master-password and the slave fails to
 85 #    connect), the slave will create a master.info file, and any later
 86 #    change in this file to the variables' values below will be ignored and
 87 #    overridden by the content of the master.info file, unless you shutdown
 88 #    the slave server, delete master.info and restart the slaver server.
 89 #    For that reason, you may want to leave the lines below untouched
 90 #    (commented) and instead use CHANGE MASTER TO (see above)
 91 #
 92 # required unique id between 2 and 2^32 - 1
 93 # (and different from the master)
 94 # defaults to 2 if master-host is set
 95 # but will not function as a slave if omitted
 96 #server-id       = 2
 97 #
 98 # The replication master for this slave - required
 99 #master-host     =   <hostname>
100 #
101 # The username the slave will use for authentication when connecting
102 # to the master - required
103 #master-user     =   <username>
104 #
105 # The password the slave will authenticate with when connecting to
106 # the master - required
107 #master-password =   <password>
108 #
109 # The port the master is listening on.
110 # optional - defaults to 3306
111 #master-port     =  <port>
112 #
113 # binary logging - not required for slaves, but recommended
114 #log-bin=mysql-bin
115 
116 # Uncomment the following if you are using InnoDB tables
117 #innodb_data_home_dir = C:\mysql\data\
118 #innodb_data_file_path = ibdata1:10M:autoextend
119 #innodb_log_group_home_dir = C:\mysql\data\
120 # You can set .._buffer_pool_size up to 50 - 80 %
121 # of RAM but beware of setting memory usage too high
122 #innodb_buffer_pool_size = 256M
123 #innodb_additional_mem_pool_size = 20M
124 # Set .._log_file_size to 25 % of buffer pool size
125 #innodb_log_file_size = 64M
126 #innodb_log_buffer_size = 8M
127 #innodb_flush_log_at_trx_commit = 1
128 #innodb_lock_wait_timeout = 50
129 
130 [mysqldump]
131 quick
132 max_allowed_packet = 16M
133 
134 [mysql]
135 no-auto-rehash
136 # Remove the next comment character if you are not familiar with SQL
137 #safe-updates
138 
139 [myisamchk]
140 key_buffer_size = 128M
141 sort_buffer_size = 128M
142 read_buffer = 2M
143 write_buffer = 2M
144 
145 [mysqlhotcopy]
146 interactive-timeout
my-large.ini
  1 #BEGIN CONFIG INFO
  2 #DESCR: 4GB RAM, InnoDB only, ACID, few connections, heavy queries
  3 #TYPE: SYSTEM
  4 #END CONFIG INFO
  5 
  6 #
  7 # This is a MySQL example config file for systems with 4GB of memory
  8 # running mostly MySQL using InnoDB only tables and performing complex
  9 # queries with few connections.
 10 # 
 11 # MySQL programs look for option files in a set of
 12 # locations which depend on the deployment platform.
 13 # You can copy this option file to one of those
 14 # locations. For information about these locations, see:
 15 # http://dev.mysql.com/doc/mysql/en/option-files.html
 16 #
 17 # In this file, you can use all long options that a program supports.
 18 # If you want to know which options a program supports, run the program
 19 # with the "--help" option.
 20 #
 21 # More detailed information about the individual options can also be
 22 # found in the manual.
 23 #
 24 
 25 #
 26 # The following options will be read by MySQL client applications.
 27 # Note that only client applications shipped by MySQL are guaranteed
 28 # to read this section. If you want your own MySQL client program to
 29 # honor these values, you need to specify it as an option during the
 30 # MySQL client library initialization.
 31 #
 32 [client]
 33 #password    = [your_password]
 34 port        = 3306
 35 socket        = /tmp/mysql.sock
 36 
 37 # *** Application-specific options follow here ***
 38 
 39 #
 40 # The MySQL server
 41 #
 42 [mysqld]
 43 
 44 # generic configuration options
 45 port        = 3306
 46 socket        = /tmp/mysql.sock
 47 
 48 # back_log is the number of connections the operating system can keep in
 49 # the listen queue, before the MySQL connection manager thread has
 50 # processed them. If you have a very high connection rate and experience
 51 # "connection refused" errors, you might need to increase this value.
 52 # Check your OS documentation for the maximum value of this parameter.
 53 # Attempting to set back_log higher than your operating system limit
 54 # will have no effect.
 55 back_log = 50
 56 
 57 # Don't listen on a TCP/IP port at all. This can be a security
 58 # enhancement, if all processes that need to connect to mysqld run
 59 # on the same host.  All interaction with mysqld must be made via Unix
 60 # sockets or named pipes.
 61 # Note that using this option without enabling named pipes on Windows
 62 # (via the "enable-named-pipe" option) will render mysqld useless!
 63 #skip-networking
 64 
 65 # The maximum amount of concurrent sessions the MySQL server will
 66 # allow. One of these connections will be reserved for a user with
 67 # SUPER privileges to allow the administrator to login even if the
 68 # connection limit has been reached.
 69 max_connections = 100
 70 
 71 # Maximum amount of errors allowed per host. If this limit is reached,
 72 # the host will be blocked from connecting to the MySQL server until
 73 # "FLUSH HOSTS" has been run or the server was restarted. Invalid
 74 # passwords and other errors during the connect phase result in
 75 # increasing this value. See the "Aborted_connects" status variable for
 76 # global counter.
 77 max_connect_errors = 10
 78 
 79 # The number of open tables for all threads. Increasing this value
 80 # increases the number of file descriptors that mysqld requires.
 81 # Therefore you have to make sure to set the amount of open files
 82 # allowed to at least 4096 in the variable "open-files-limit" in
 83 # section [mysqld_safe]
 84 table_open_cache = 2048
 85 
 86 # Enable external file level locking. Enabled file locking will have a
 87 # negative impact on performance, so only use it in case you have
 88 # multiple database instances running on the same files (note some
 89 # restrictions still apply!) or if you use other software relying on
 90 # locking MyISAM tables on file level.
 91 #external-locking
 92 
 93 # The maximum size of a query packet the server can handle as well as
 94 # maximum query size server can process (Important when working with
 95 # large BLOBs).  enlarged dynamically, for each connection.
 96 max_allowed_packet = 16M
 97 
 98 # The size of the cache to hold the SQL statements for the binary log
 99 # during a transaction. If you often use big, multi-statement
100 # transactions you can increase this value to get more performance. All
101 # statements from transactions are buffered in the binary log cache and
102 # are being written to the binary log at once after the COMMIT.  If the
103 # transaction is larger than this value, temporary file on disk is used
104 # instead.  This buffer is allocated per connection on first update
105 # statement in transaction
106 binlog_cache_size = 1M
107 
108 # Maximum allowed size for a single HEAP (in memory) table. This option
109 # is a protection against the accidential creation of a very large HEAP
110 # table which could otherwise use up all memory resources.
111 max_heap_table_size = 64M
112 
113 # Size of the buffer used for doing full table scans.
114 # Allocated per thread, if a full scan is needed.
115 read_buffer_size = 2M
116 
117 # When reading rows in sorted order after a sort, the rows are read
118 # through this buffer to avoid disk seeks. You can improve ORDER BY
119 # performance a lot, if set this to a high value.
120 # Allocated per thread, when needed.
121 read_rnd_buffer_size = 16M
122 
123 # Sort buffer is used to perform sorts for some ORDER BY and GROUP BY
124 # queries. If sorted data does not fit into the sort buffer, a disk
125 # based merge sort is used instead - See the "Sort_merge_passes"
126 # status variable. Allocated per thread if sort is needed.
127 sort_buffer_size = 8M
128 
129 # This buffer is used for the optimization of full JOINs (JOINs without
130 # indexes). Such JOINs are very bad for performance in most cases
131 # anyway, but setting this variable to a large value reduces the
132 # performance impact. See the "Select_full_join" status variable for a
133 # count of full JOINs. Allocated per thread if full join is found
134 join_buffer_size = 8M
135 
136 # How many threads we should keep in a cache for reuse. When a client
137 # disconnects, the client's threads are put in the cache if there aren't
138 # more than thread_cache_size threads from before.  This greatly reduces
139 # the amount of thread creations needed if you have a lot of new
140 # connections. (Normally this doesn't give a notable performance
141 # improvement if you have a good thread implementation.)
142 thread_cache_size = 8
143 
144 # This permits the application to give the threads system a hint for the
145 # desired number of threads that should be run at the same time.  This
146 # value only makes sense on systems that support the thread_concurrency()
147 # function call (Sun Solaris, for example).
148 # You should try [number of CPUs]*(2..4) for thread_concurrency
149 thread_concurrency = 8
150 
151 # Query cache is used to cache SELECT results and later return them
152 # without actual executing the same query once again. Having the query
153 # cache enabled may result in significant speed improvements, if your
154 # have a lot of identical queries and rarely changing tables. See the
155 # "Qcache_lowmem_prunes" status variable to check if the current value
156 # is high enough for your load.
157 # Note: In case your tables change very often or if your queries are
158 # textually different every time, the query cache may result in a
159 # slowdown instead of a performance improvement.
160 query_cache_size = 64M
161 
162 # Only cache result sets that are smaller than this limit. This is to
163 # protect the query cache of a very large result set overwriting all
164 # other query results.
165 query_cache_limit = 2M
166 
167 # Minimum word length to be indexed by the full text search index.
168 # You might wish to decrease it if you need to search for shorter words.
169 # Note that you need to rebuild your FULLTEXT index, after you have
170 # modified this value.
171 ft_min_word_len = 4
172 
173 # If your system supports the memlock() function call, you might want to
174 # enable this option while running MySQL to keep it locked in memory and
175 # to avoid potential swapping out in case of high memory pressure. Good
176 # for performance.
177 #memlock
178 
179 # Table type which is used by default when creating new tables, if not
180 # specified differently during the CREATE TABLE statement.
181 default-storage-engine = MYISAM
182 
183 # Thread stack size to use. This amount of memory is always reserved at
184 # connection time. MySQL itself usually needs no more than 64K of
185 # memory, while if you use your own stack hungry UDF functions or your
186 # OS requires more stack for some operations, you might need to set this
187 # to a higher value.
188 thread_stack = 192K
189 
190 # Set the default transaction isolation level. Levels available are:
191 # READ-UNCOMMITTED, READ-COMMITTED, REPEATABLE-READ, SERIALIZABLE
192 transaction_isolation = REPEATABLE-READ
193 
194 # Maximum size for internal (in-memory) temporary tables. If a table
195 # grows larger than this value, it is automatically converted to disk
196 # based table This limitation is for a single table. There can be many
197 # of them.
198 tmp_table_size = 64M
199 
200 # Enable binary logging. This is required for acting as a MASTER in a
201 # replication configuration. You also need the binary log if you need
202 # the ability to do point in time recovery from your latest backup.
203 log-bin=mysql-bin
204 
205 # binary logging format - mixed recommended
206 binlog_format=mixed
207 
208 # If you're using replication with chained slaves (A->B->C), you need to
209 # enable this option on server B. It enables logging of updates done by
210 # the slave thread into the slave's binary log.
211 #log_slave_updates
212 
213 # Enable the full query log. Every query (even ones with incorrect
214 # syntax) that the server receives will be logged. This is useful for
215 # debugging, it is usually disabled in production use.
216 #log
217 
218 # Print warnings to the error log file.  If you have any problem with
219 # MySQL you should enable logging of warnings and examine the error log
220 # for possible explanations. 
221 #log_warnings
222 
223 # Log slow queries. Slow queries are queries which take more than the
224 # amount of time defined in "long_query_time" or which do not use
225 # indexes well, if log_short_format is not enabled. It is normally good idea
226 # to have this turned on if you frequently add new queries to the
227 # system.
228 slow_query_log
229 
230 # All queries taking more than this amount of time (in seconds) will be
231 # trated as slow. Do not use "1" as a value here, as this will result in
232 # even very fast queries being logged from time to time (as MySQL
233 # currently measures time with second accuracy only).
234 long_query_time = 2
235 
236 
237 # ***  Replication related settings 
238 
239 
240 # Unique server identification number between 1 and 2^32-1. This value
241 # is required for both master and slave hosts. It defaults to 1 if
242 # "master-host" is not set, but will MySQL will not function as a master
243 # if it is omitted.
244 server-id = 1
245 
246 # Replication Slave (comment out master section to use this)
247 #
248 # To configure this host as a replication slave, you can choose between
249 # two methods :
250 #
251 # 1) Use the CHANGE MASTER TO command (fully described in our manual) -
252 #    the syntax is:
253 #
254 #    CHANGE MASTER TO MASTER_HOST=<host>, MASTER_PORT=<port>,
255 #    MASTER_USER=<user>, MASTER_PASSWORD=<password> ;
256 #
257 #    where you replace <host>, <user>, <password> by quoted strings and
258 #    <port> by the master's port number (3306 by default).
259 #
260 #    Example:
261 #
262 #    CHANGE MASTER TO MASTER_HOST='125.564.12.1', MASTER_PORT=3306,
263 #    MASTER_USER='joe', MASTER_PASSWORD='secret';
264 #
265 # OR
266 #
267 # 2) Set the variables below. However, in case you choose this method, then
268 #    start replication for the first time (even unsuccessfully, for example
269 #    if you mistyped the password in master-password and the slave fails to
270 #    connect), the slave will create a master.info file, and any later
271 #    changes in this file to the variable values below will be ignored and
272 #    overridden by the content of the master.info file, unless you shutdown
273 #    the slave server, delete master.info and restart the slaver server.
274 #    For that reason, you may want to leave the lines below untouched
275 #    (commented) and instead use CHANGE MASTER TO (see above)
276 #
277 # required unique id between 2 and 2^32 - 1
278 # (and different from the master)
279 # defaults to 2 if master-host is set
280 # but will not function as a slave if omitted
281 #server-id = 2
282 #
283 # The replication master for this slave - required
284 #master-host = <hostname>
285 #
286 # The username the slave will use for authentication when connecting
287 # to the master - required
288 #master-user = <username>
289 #
290 # The password the slave will authenticate with when connecting to
291 # the master - required
292 #master-password = <password>
293 #
294 # The port the master is listening on.
295 # optional - defaults to 3306
296 #master-port = <port>
297 
298 # Make the slave read-only. Only users with the SUPER privilege and the
299 # replication slave thread will be able to modify data on it. You can
300 # use this to ensure that no applications will accidently modify data on
301 # the slave instead of the master
302 #read_only
303 
304 
305 #*** MyISAM Specific options
306 
307 
308 # Size of the Key Buffer, used to cache index blocks for MyISAM tables.
309 # Do not set it larger than 30% of your available memory, as some memory
310 # is also required by the OS to cache rows. Even if you're not using
311 # MyISAM tables, you should still set it to 8-64M as it will also be
312 # used for internal temporary disk tables.
313 key_buffer_size = 32M
314 
315 # MyISAM uses special tree-like cache to make bulk inserts (that is,
316 # INSERT ... SELECT, INSERT ... VALUES (...), (...), ..., and LOAD DATA
317 # INFILE) faster. This variable limits the size of the cache tree in
318 # bytes per thread. Setting it to 0 will disable this optimisation.  Do
319 # not set it larger than "key_buffer_size" for optimal performance.
320 # This buffer is allocated when a bulk insert is detected.
321 bulk_insert_buffer_size = 64M
322 
323 # This buffer is allocated when MySQL needs to rebuild the index in
324 # REPAIR, OPTIMIZE, ALTER table statements as well as in LOAD DATA INFILE
325 # into an empty table. It is allocated per thread so be careful with
326 # large settings.
327 myisam_sort_buffer_size = 128M
328 
329 # The maximum size of the temporary file MySQL is allowed to use while
330 # recreating the index (during REPAIR, ALTER TABLE or LOAD DATA INFILE.
331 # If the file-size would be bigger than this, the index will be created
332 # through the key cache (which is slower).
333 myisam_max_sort_file_size = 10G
334 
335 # If a table has more than one index, MyISAM can use more than one
336 # thread to repair them by sorting in parallel. This makes sense if you
337 # have multiple CPUs and plenty of memory.
338 myisam_repair_threads = 1
339 
340 # Automatically check and repair not properly closed MyISAM tables.
341 myisam_recover
342 
343 # *** INNODB Specific options ***
344 
345 # Use this option if you have a MySQL server with InnoDB support enabled
346 # but you do not plan to use it. This will save memory and disk space
347 # and speed up some things.
348 #skip-innodb
349 
350 # Additional memory pool that is used by InnoDB to store metadata
351 # information.  If InnoDB requires more memory for this purpose it will
352 # start to allocate it from the OS.  As this is fast enough on most
353 # recent operating systems, you normally do not need to change this
354 # value. SHOW INNODB STATUS will display the current amount used.
355 innodb_additional_mem_pool_size = 16M
356 
357 # InnoDB, unlike MyISAM, uses a buffer pool to cache both indexes and
358 # row data. The bigger you set this the less disk I/O is needed to
359 # access data in tables. On a dedicated database server you may set this
360 # parameter up to 80% of the machine physical memory size. Do not set it
361 # too large, though, because competition of the physical memory may
362 # cause paging in the operating system.  Note that on 32bit systems you
363 # might be limited to 2-3.5G of user level memory per process, so do not
364 # set it too high.
365 innodb_buffer_pool_size = 2G
366 
367 # InnoDB stores data in one or more data files forming the tablespace.
368 # If you have a single logical drive for your data, a single
369 # autoextending file would be good enough. In other cases, a single file
370 # per device is often a good choice. You can configure InnoDB to use raw
371 # disk partitions as well - please refer to the manual for more info
372 # about this.
373 innodb_data_file_path = ibdata1:10M:autoextend
374 
375 # Set this option if you would like the InnoDB tablespace files to be
376 # stored in another location. By default this is the MySQL datadir.
377 #innodb_data_home_dir = <directory>
378 
379 # Number of IO threads to use for async IO operations. This value is
380 # hardcoded to 8 on Unix, but on Windows disk I/O may benefit from a
381 # larger number.
382 innodb_write_io_threads = 8
383 innodb_read_io_threads = 8
384 
385 # If you run into InnoDB tablespace corruption, setting this to a nonzero
386 # value will likely help you to dump your tables. Start from value 1 and
387 # increase it until you're able to dump the table successfully.
388 #innodb_force_recovery=1
389 
390 # Number of threads allowed inside the InnoDB kernel. The optimal value
391 # depends highly on the application, hardware as well as the OS
392 # scheduler properties. A too high value may lead to thread thrashing.
393 innodb_thread_concurrency = 16
394 
395 # If set to 1, InnoDB will flush (fsync) the transaction logs to the
396 # disk at each commit, which offers full ACID behavior. If you are
397 # willing to compromise this safety, and you are running small
398 # transactions, you may set this to 0 or 2 to reduce disk I/O to the
399 # logs. Value 0 means that the log is only written to the log file and
400 # the log file flushed to disk approximately once per second. Value 2
401 # means the log is written to the log file at each commit, but the log
402 # file is only flushed to disk approximately once per second.
403 innodb_flush_log_at_trx_commit = 1
404 
405 # Speed up InnoDB shutdown. This will disable InnoDB to do a full purge
406 # and insert buffer merge on shutdown. It may increase shutdown time a
407 # lot, but InnoDB will have to do it on the next startup instead.
408 #innodb_fast_shutdown
409 
410 # The size of the buffer InnoDB uses for buffering log data. As soon as
411 # it is full, InnoDB will have to flush it to disk. As it is flushed
412 # once per second anyway, it does not make sense to have it very large
413 # (even with long transactions). 
414 innodb_log_buffer_size = 8M
415 
416 # Size of each log file in a log group. You should set the combined size
417 # of log files to about 25%-100% of your buffer pool size to avoid
418 # unneeded buffer pool flush activity on log file overwrite. However,
419 # note that a larger logfile size will increase the time needed for the
420 # recovery process.
421 innodb_log_file_size = 256M
422 
423 # Total number of files in the log group. A value of 2-3 is usually good
424 # enough.
425 innodb_log_files_in_group = 3
426 
427 # Location of the InnoDB log files. Default is the MySQL datadir. You
428 # may wish to point it to a dedicated hard drive or a RAID1 volume for
429 # improved performance
430 #innodb_log_group_home_dir
431 
432 # Maximum allowed percentage of dirty pages in the InnoDB buffer pool.
433 # If it is reached, InnoDB will start flushing them out agressively to
434 # not run out of clean pages at all. This is a soft limit, not
435 # guaranteed to be held.
436 innodb_max_dirty_pages_pct = 90
437 
438 # The flush method InnoDB will use for Log. The tablespace always uses
439 # doublewrite flush logic. The default value is "fdatasync", another
440 # option is "O_DSYNC".
441 #innodb_flush_method=O_DSYNC
442 
443 # How long an InnoDB transaction should wait for a lock to be granted
444 # before being rolled back. InnoDB automatically detects transaction
445 # deadlocks in its own lock table and rolls back the transaction. If you
446 # use the LOCK TABLES command, or other transaction-safe storage engines
447 # than InnoDB in the same transaction, then a deadlock may arise which
448 # InnoDB cannot notice. In cases like this the timeout is useful to
449 # resolve the situation.
450 innodb_lock_wait_timeout = 120
451 
452 
453 [mysqldump]
454 # Do not buffer the whole result set in memory before writing it to
455 # file. Required for dumping very large tables
456 quick
457 
458 max_allowed_packet = 16M
459 
460 [mysql]
461 no-auto-rehash
462 
463 # Only allow UPDATEs and DELETEs that use keys.
464 #safe-updates
465 
466 [myisamchk]
467 key_buffer_size = 512M
468 sort_buffer_size = 512M
469 read_buffer = 8M
470 write_buffer = 8M
471 
472 [mysqlhotcopy]
473 interactive-timeout
474 
475 [mysqld_safe]
476 # Increase the amount of open files allowed per process. Warning: Make
477 # sure you have set the global system limit high enough! The high value
478 # is required for a large number of opened tables
479 open-files-limit = 8192
my-innodb-heavy-4G.ini
  1 # Example MySQL config file for very large systems.
  2 #
  3 # This is for a large system with memory of 1G-2G where the system runs mainly
  4 # MySQL.
  5 #
  6 # MySQL programs look for option files in a set of
  7 # locations which depend on the deployment platform.
  8 # You can copy this option file to one of those
  9 # locations. For information about these locations, see:
 10 # http://dev.mysql.com/doc/mysql/en/option-files.html
 11 #
 12 # In this file, you can use all long options that a program supports.
 13 # If you want to know which options a program supports, run the program
 14 # with the "--help" option.
 15 
 16 # The following options will be passed to all MySQL clients
 17 [client]
 18 #password    = your_password
 19 port        = 3306
 20 socket        = /tmp/mysql.sock
 21 
 22 # Here follows entries for some specific programs
 23 
 24 # The MySQL server
 25 [mysqld]
 26 port        = 3306
 27 socket        = /tmp/mysql.sock
 28 skip-external-locking
 29 key_buffer_size = 384M
 30 max_allowed_packet = 1M
 31 table_open_cache = 512
 32 sort_buffer_size = 2M
 33 read_buffer_size = 2M
 34 read_rnd_buffer_size = 8M
 35 myisam_sort_buffer_size = 64M
 36 thread_cache_size = 8
 37 query_cache_size = 32M
 38 # Try number of CPU's*2 for thread_concurrency
 39 thread_concurrency = 8
 40 
 41 # Don't listen on a TCP/IP port at all. This can be a security enhancement,
 42 # if all processes that need to connect to mysqld run on the same host.
 43 # All interaction with mysqld must be made via Unix sockets or named pipes.
 44 # Note that using this option without enabling named pipes on Windows
 45 # (via the "enable-named-pipe" option) will render mysqld useless!
 46 # 
 47 #skip-networking
 48 
 49 # Replication Master Server (default)
 50 # binary logging is required for replication
 51 log-bin=mysql-bin
 52 
 53 # required unique id between 1 and 2^32 - 1
 54 # defaults to 1 if master-host is not set
 55 # but will not function as a master if omitted
 56 server-id    = 1
 57 
 58 # Replication Slave (comment out master section to use this)
 59 #
 60 # To configure this host as a replication slave, you can choose between
 61 # two methods :
 62 #
 63 # 1) Use the CHANGE MASTER TO command (fully described in our manual) -
 64 #    the syntax is:
 65 #
 66 #    CHANGE MASTER TO MASTER_HOST=<host>, MASTER_PORT=<port>,
 67 #    MASTER_USER=<user>, MASTER_PASSWORD=<password> ;
 68 #
 69 #    where you replace <host>, <user>, <password> by quoted strings and
 70 #    <port> by the master's port number (3306 by default).
 71 #
 72 #    Example:
 73 #
 74 #    CHANGE MASTER TO MASTER_HOST='125.564.12.1', MASTER_PORT=3306,
 75 #    MASTER_USER='joe', MASTER_PASSWORD='secret';
 76 #
 77 # OR
 78 #
 79 # 2) Set the variables below. However, in case you choose this method, then
 80 #    start replication for the first time (even unsuccessfully, for example
 81 #    if you mistyped the password in master-password and the slave fails to
 82 #    connect), the slave will create a master.info file, and any later
 83 #    change in this file to the variables' values below will be ignored and
 84 #    overridden by the content of the master.info file, unless you shutdown
 85 #    the slave server, delete master.info and restart the slaver server.
 86 #    For that reason, you may want to leave the lines below untouched
 87 #    (commented) and instead use CHANGE MASTER TO (see above)
 88 #
 89 # required unique id between 2 and 2^32 - 1
 90 # (and different from the master)
 91 # defaults to 2 if master-host is set
 92 # but will not function as a slave if omitted
 93 #server-id       = 2
 94 #
 95 # The replication master for this slave - required
 96 #master-host     =   <hostname>
 97 #
 98 # The username the slave will use for authentication when connecting
 99 # to the master - required
100 #master-user     =   <username>
101 #
102 # The password the slave will authenticate with when connecting to
103 # the master - required
104 #master-password =   <password>
105 #
106 # The port the master is listening on.
107 # optional - defaults to 3306
108 #master-port     =  <port>
109 #
110 # binary logging - not required for slaves, but recommended
111 #log-bin=mysql-bin
112 #
113 # binary logging format - mixed recommended 
114 #binlog_format=mixed
115 
116 # Uncomment the following if you are using InnoDB tables
117 #innodb_data_home_dir = C:\mysql\data\
118 #innodb_data_file_path = ibdata1:2000M;ibdata2:10M:autoextend
119 #innodb_log_group_home_dir = C:\mysql\data\
120 # You can set .._buffer_pool_size up to 50 - 80 %
121 # of RAM but beware of setting memory usage too high
122 #innodb_buffer_pool_size = 384M
123 #innodb_additional_mem_pool_size = 20M
124 # Set .._log_file_size to 25 % of buffer pool size
125 #innodb_log_file_size = 100M
126 #innodb_log_buffer_size = 8M
127 #innodb_flush_log_at_trx_commit = 1
128 #innodb_lock_wait_timeout = 50
129 
130 [mysqldump]
131 quick
132 max_allowed_packet = 16M
133 
134 [mysql]
135 no-auto-rehash
136 # Remove the next comment character if you are not familiar with SQL
137 #safe-updates
138 
139 [myisamchk]
140 key_buffer_size = 256M
141 sort_buffer_size = 256M
142 read_buffer = 2M
143 write_buffer = 2M
144 
145 [mysqlhotcopy]
146 interactive-timeout
my-huge.ini

手順③

 環境変数の定義

手順④

システム管理者として、命令「CMD」を開く、下記命令を行う

①初期化my.ini

C:mysql-8.0.13-winx64in>mysqld --defaults-file="%MYSQL_HOME%inmy.ini" --initialize --console

②初期パスワードを取得

手順⑤

Windowsのサービスをインストールする

①命令:mysqld -install [サービス名]

②命令:

  net start MySQL(起動)/ net stop MySQL(停止)/ sc delete MySQL(削除)

手順⑥

MysqlのDB起動

命令:

  mysql -h ホストネーム:ポート -u ユーザID -p

  (例:mysql -h localhost:3306 -u root -p)

パスワード変更:

  方法一:

    c:>mysqladmin -u root -p [旧パスワード] [新パスワード]

  方法二(MySQL5 OR MySQL8、違う):

    mysql>ALTER USER 'root'@'localhost' IDENTIFIED BY '新パスワード';

    mysql>ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '新パスワード';

 ■参考

https://www.jianshu.com/p/d4f617bf43a1

以上。

原文地址:https://www.cnblogs.com/lnsylt/p/10275080.html