Sean Dague | e263c82 | 2014-12-05 14:25:28 -0500 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # |
Dean Troyer | 6d04fd7 | 2012-12-21 11:03:37 -0600 | [diff] [blame] | 3 | # lib/databases/mysql |
| 4 | # Functions to control the configuration and operation of the **MySQL** database backend |
Terry Wilson | 428af5a | 2012-11-01 16:12:39 -0400 | [diff] [blame] | 5 | |
| 6 | # Dependencies: |
Adam Spiers | 6a5aa7c | 2013-10-24 11:27:02 +0100 | [diff] [blame] | 7 | # |
| 8 | # - DATABASE_{HOST,USER,PASSWORD} must be defined |
Terry Wilson | 428af5a | 2012-11-01 16:12:39 -0400 | [diff] [blame] | 9 | |
| 10 | # Save trace setting |
Ian Wienand | 523f488 | 2015-10-13 11:03:03 +1100 | [diff] [blame] | 11 | _XTRACE_DB_MYSQL=$(set +o | grep xtrace) |
Terry Wilson | 428af5a | 2012-11-01 16:12:39 -0400 | [diff] [blame] | 12 | set +o xtrace |
| 13 | |
armando-migliaccio | b3d8822 | 2015-06-12 07:54:03 -0700 | [diff] [blame] | 14 | MYSQL_DRIVER=${MYSQL_DRIVER:-PyMySQL} |
Dean Troyer | cc6b443 | 2013-04-08 15:38:03 -0500 | [diff] [blame] | 15 | |
Terry Wilson | 428af5a | 2012-11-01 16:12:39 -0400 | [diff] [blame] | 16 | register_database mysql |
| 17 | |
Sean Dague | 5375329 | 2014-12-04 19:38:15 -0500 | [diff] [blame] | 18 | # Linux distros, thank you for being incredibly consistent |
| 19 | MYSQL=mysql |
Wiekus Beukes | ec47bc1 | 2015-03-19 08:20:38 -0700 | [diff] [blame] | 20 | if is_fedora && ! is_oraclelinux; then |
Attila Fazekas | 1f316be | 2015-01-26 16:39:57 +0100 | [diff] [blame] | 21 | MYSQL=mariadb |
Sean Dague | 5375329 | 2014-12-04 19:38:15 -0500 | [diff] [blame] | 22 | fi |
Dean Troyer | cc6b443 | 2013-04-08 15:38:03 -0500 | [diff] [blame] | 23 | |
| 24 | # Functions |
| 25 | # --------- |
| 26 | |
Julien Danjou | 0eec4f8 | 2015-09-08 10:45:06 +0000 | [diff] [blame] | 27 | function get_database_type_mysql { |
| 28 | if [[ "$MYSQL_DRIVER" == "PyMySQL" ]]; then |
| 29 | echo mysql+pymysql |
| 30 | else |
| 31 | echo mysql |
| 32 | fi |
| 33 | } |
| 34 | |
Dean Troyer | 995eb92 | 2013-03-07 16:11:40 -0600 | [diff] [blame] | 35 | # Get rid of everything enough to cleanly change database backends |
| 36 | function cleanup_database_mysql { |
Sean Dague | 5375329 | 2014-12-04 19:38:15 -0500 | [diff] [blame] | 37 | stop_service $MYSQL |
Dean Troyer | 995eb92 | 2013-03-07 16:11:40 -0600 | [diff] [blame] | 38 | if is_ubuntu; then |
| 39 | # Get ruthless with mysql |
Sean Dague | 8f90f76 | 2015-01-14 10:36:48 -0500 | [diff] [blame] | 40 | apt_get purge -y mysql* mariadb* |
Dean Troyer | 995eb92 | 2013-03-07 16:11:40 -0600 | [diff] [blame] | 41 | sudo rm -rf /var/lib/mysql |
Tiago Mello | 4376ae0 | 2014-03-14 10:48:56 -0300 | [diff] [blame] | 42 | sudo rm -rf /etc/mysql |
Dean Troyer | 995eb92 | 2013-03-07 16:11:40 -0600 | [diff] [blame] | 43 | return |
Wiekus Beukes | ec47bc1 | 2015-03-19 08:20:38 -0700 | [diff] [blame] | 44 | elif is_suse || is_oraclelinux; then |
| 45 | uninstall_package mysql-community-server |
| 46 | sudo rm -rf /var/lib/mysql |
Dean Troyer | 995eb92 | 2013-03-07 16:11:40 -0600 | [diff] [blame] | 47 | elif is_fedora; then |
Attila Fazekas | 1f316be | 2015-01-26 16:39:57 +0100 | [diff] [blame] | 48 | uninstall_package mariadb-server |
| 49 | sudo rm -rf /var/lib/mysql |
Dean Troyer | 995eb92 | 2013-03-07 16:11:40 -0600 | [diff] [blame] | 50 | else |
| 51 | return |
| 52 | fi |
Dean Troyer | 995eb92 | 2013-03-07 16:11:40 -0600 | [diff] [blame] | 53 | } |
| 54 | |
Terry Wilson | 428af5a | 2012-11-01 16:12:39 -0400 | [diff] [blame] | 55 | function recreate_database_mysql { |
| 56 | local db=$1 |
zhhuabj | 2832f28 | 2013-05-08 18:43:26 +0800 | [diff] [blame] | 57 | mysql -u$DATABASE_USER -p$DATABASE_PASSWORD -h$MYSQL_HOST -e "DROP DATABASE IF EXISTS $db;" |
Ihar Hrachyshka | 157c84b | 2014-10-06 13:29:39 +0200 | [diff] [blame] | 58 | mysql -u$DATABASE_USER -p$DATABASE_PASSWORD -h$MYSQL_HOST -e "CREATE DATABASE $db CHARACTER SET utf8;" |
Terry Wilson | 428af5a | 2012-11-01 16:12:39 -0400 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | function configure_database_mysql { |
Dean Troyer | 3ef23bc | 2014-07-25 14:56:22 -0500 | [diff] [blame] | 62 | local my_conf mysql slow_log |
Terry Wilson | 428af5a | 2012-11-01 16:12:39 -0400 | [diff] [blame] | 63 | echo_summary "Configuring and starting MySQL" |
| 64 | |
Vincent Untz | c18b965 | 2012-12-04 12:36:34 +0100 | [diff] [blame] | 65 | if is_ubuntu; then |
Dean Troyer | 3ef23bc | 2014-07-25 14:56:22 -0500 | [diff] [blame] | 66 | my_conf=/etc/mysql/my.cnf |
| 67 | mysql=mysql |
Wiekus Beukes | ec47bc1 | 2015-03-19 08:20:38 -0700 | [diff] [blame] | 68 | elif is_suse || is_oraclelinux; then |
| 69 | my_conf=/etc/my.cnf |
| 70 | mysql=mysql |
Vincent Untz | 00011c0 | 2012-12-06 09:56:32 +0100 | [diff] [blame] | 71 | elif is_fedora; then |
Attila Fazekas | 1f316be | 2015-01-26 16:39:57 +0100 | [diff] [blame] | 72 | mysql=mariadb |
Dean Troyer | 3ef23bc | 2014-07-25 14:56:22 -0500 | [diff] [blame] | 73 | my_conf=/etc/my.cnf |
Vincent Untz | 00011c0 | 2012-12-06 09:56:32 +0100 | [diff] [blame] | 74 | else |
| 75 | exit_distro_not_supported "mysql configuration" |
Terry Wilson | 428af5a | 2012-11-01 16:12:39 -0400 | [diff] [blame] | 76 | fi |
| 77 | |
| 78 | # Start mysql-server |
Vincent Untz | 00011c0 | 2012-12-06 09:56:32 +0100 | [diff] [blame] | 79 | if is_fedora || is_suse; then |
| 80 | # service is not started by default |
Dean Troyer | 3ef23bc | 2014-07-25 14:56:22 -0500 | [diff] [blame] | 81 | start_service $mysql |
Vincent Untz | 00011c0 | 2012-12-06 09:56:32 +0100 | [diff] [blame] | 82 | fi |
| 83 | |
| 84 | # Set the root password - only works the first time. For Ubuntu, we already |
Jens Rosenboom | 9abb26d | 2016-12-07 21:12:55 +0100 | [diff] [blame] | 85 | # did that with debconf before installing the package, but we still try, |
| 86 | # because the package might have been installed already. |
| 87 | sudo mysqladmin -u root password $DATABASE_PASSWORD || true |
Vincent Untz | 00011c0 | 2012-12-06 09:56:32 +0100 | [diff] [blame] | 88 | |
Marian Horban | ea21eb4 | 2015-08-18 06:57:18 -0400 | [diff] [blame] | 89 | # Update the DB to give user '$DATABASE_USER'@'%' full control of the all databases: |
Terry Wilson | 428af5a | 2012-11-01 16:12:39 -0400 | [diff] [blame] | 90 | sudo mysql -uroot -p$DATABASE_PASSWORD -h127.0.0.1 -e "GRANT ALL PRIVILEGES ON *.* TO '$DATABASE_USER'@'%' identified by '$DATABASE_PASSWORD';" |
| 91 | |
| 92 | # Now update ``my.cnf`` for some local needs and restart the mysql service |
| 93 | |
Marian Horban | ea21eb4 | 2015-08-18 06:57:18 -0400 | [diff] [blame] | 94 | # Change bind-address from localhost (127.0.0.1) to any (::) and |
Ralf Haferkamp | 0526bb8 | 2014-04-03 08:27:33 +0200 | [diff] [blame] | 95 | # set default db type to InnoDB |
Ian Wienand | 9c0b9f3 | 2015-07-22 06:08:09 +1000 | [diff] [blame] | 96 | iniset -sudo $my_conf mysqld bind-address "$SERVICE_LISTEN_ADDRESS" |
Roman Podoliaka | 88b8409 | 2017-02-07 13:34:12 +0200 | [diff] [blame] | 97 | iniset -sudo $my_conf mysqld sql_mode TRADITIONAL |
Ian Wienand | 9c0b9f3 | 2015-07-22 06:08:09 +1000 | [diff] [blame] | 98 | iniset -sudo $my_conf mysqld default-storage-engine InnoDB |
Amrith Kumar | 1e66388 | 2017-02-27 13:29:03 -0500 | [diff] [blame^] | 99 | |
| 100 | # the number of connections has been throttled to 256. In the |
| 101 | # event that the gate jobs report "Too many connections" it is |
| 102 | # indicative of a problem that could be the result of one of many |
| 103 | # things. For more details about debugging this error, refer |
| 104 | # https://dev.mysql.com/doc/refman/5.5/en/too-many-connections.html. |
| 105 | # Note that the problem may not ONLY be an issue with MySQL |
| 106 | # connections. If the number of fd's at the OS is too low, you |
| 107 | # could see errors manifest as MySQL "too many connections". |
| 108 | iniset -sudo $my_conf mysqld max_connections 256 |
Ian Wienand | 9c0b9f3 | 2015-07-22 06:08:09 +1000 | [diff] [blame] | 109 | iniset -sudo $my_conf mysqld query_cache_type OFF |
| 110 | iniset -sudo $my_conf mysqld query_cache_size 0 |
Terry Wilson | 428af5a | 2012-11-01 16:12:39 -0400 | [diff] [blame] | 111 | |
Amrith Kumar | 1e66388 | 2017-02-27 13:29:03 -0500 | [diff] [blame^] | 112 | # Additional settings to put MySQL on a memory diet. These |
| 113 | # settings are used in conjunction with the cap on max_connections |
| 114 | # as the total memory used by MySQL can be simply viewed as |
| 115 | # fixed-allocations + max_connections * variable-allocations. A |
| 116 | # nifty tool to help with this is |
| 117 | # http://www.mysqlcalculator.com/. A short description of each of |
| 118 | # the settings follows. |
| 119 | |
| 120 | # binlog_cache_size, determines the size of cache to hold changes |
| 121 | # to the binary log during a transaction, for each connection. For |
| 122 | # more details, refer |
| 123 | # https://dev.mysql.com/doc/refman/5.6/en/replication-options-binary-log.html#sysvar_binlog_cache_size |
| 124 | # When binary logging is enabled, a smaller binlog cache could |
| 125 | # result in more frequent flushes to the disk and a larger value |
| 126 | # would result in less flushes to the disk but higher memory |
| 127 | # usage. This however only has to do with large transactions; if |
| 128 | # you have a small transaction the binlog cache is necessarily |
| 129 | # flushed on a transaction commit. This is a per-connection cache. |
| 130 | iniset -sudo $my_conf mysqld binlog_cache_size 4K |
| 131 | |
| 132 | # binlog_stmt_cache_size determines the size of cache to hold non |
| 133 | # transactional statements in the binary log. For more details, |
| 134 | # refer |
| 135 | # https://dev.mysql.com/doc/refman/5.6/en/replication-options-binary-log.html#sysvar_binlog_stmt_cache_size |
| 136 | # This cache holds changes to non-transactional tables (read: |
| 137 | # MyISAM) or any non-transactional statements which cause |
| 138 | # modifications to data (truncate is an example). These are |
| 139 | # written to disk immediately on completion of the statement or |
| 140 | # when the cache is full. If the cache is too small, you get |
| 141 | # frequent writes to the disk (flush) and if the cache is too |
| 142 | # large, it takes up more memory. This is a per-connection cache. |
| 143 | iniset -sudo $my_conf mysqld binlog_stmt_cache_size 4K |
| 144 | |
| 145 | # bulk_insert_buffer_size for MyISAM tables that use a special |
| 146 | # cache for insert statements and load statements, this cache is |
| 147 | # used to optimize writes to the disk. If the value is set to 0, |
| 148 | # the optimization is disabled. For more details refer |
| 149 | # https://dev.mysql.com/doc/refman/5.7/en/server-system-variables.html#sysvar_bulk_insert_buffer_size |
| 150 | # We set this to 0 which could result in higher disk I/O (I/O on |
| 151 | # each insert block completion). |
| 152 | iniset -sudo $my_conf mysqld bulk_insert_buffer_size 0 |
| 153 | |
| 154 | # host_cache_size controls a DNS lookup optimization. For more |
| 155 | # details refer |
| 156 | # https://dev.mysql.com/doc/refman/5.6/en/host-cache.html |
| 157 | iniset -sudo $my_conf mysqld host_cache_size 0 |
| 158 | |
| 159 | # innodb_buffer_pool_size This is the size of the server wide |
| 160 | # buffer pool. It is the cache for all data blocks being used by |
| 161 | # the server and is managed as a LRU chain. Dirty blocks either |
| 162 | # age off the list or are forced off when the list is |
| 163 | # full. Setting this to 5MB (default 128MB) reduces the amount of |
| 164 | # memory used by the server and this will result in more disk I/O |
| 165 | # in cases where (a) there is considerable write activity that |
| 166 | # overwhelms the allocated cache, or (b) there is considerable |
| 167 | # read activity on a data set that exceeds the allocated |
| 168 | # cache. For more details, refer |
| 169 | # https://dev.mysql.com/doc/refman/5.6/en/innodb-parameters.html#sysvar_innodb_buffer_pool_size |
| 170 | iniset -sudo $my_conf mysqld innodb_buffer_pool_size 5M |
| 171 | |
| 172 | # innodb_ft_cache_size and innodb_ft_total_cache_size control the |
| 173 | # per-connection full text search cache and the server wide |
| 174 | # maximum full text search cache. We should not be using full text |
| 175 | # search and the value is set to the minimum allowable. The former |
| 176 | # is a per-connection cache size and the latter is server |
| 177 | # wide. For more details, refer |
| 178 | # https://dev.mysql.com/doc/refman/5.7/en/innodb-parameters.html#sysvar_innodb_ft_cache_size |
| 179 | # and |
| 180 | # https://dev.mysql.com/doc/refman/5.7/en/innodb-parameters.html#sysvar_innodb_ft_total_cache_size |
| 181 | iniset -sudo $my_conf mysqld innodb_ft_cache_size 1600000 |
| 182 | iniset -sudo $my_conf mysqld innodb_ft_total_cache_size 32000000 |
| 183 | |
| 184 | # innodb_log_buffer_size This buffer is used to buffer |
| 185 | # transactions in-memory before writing them to the innodb |
| 186 | # internal transaction log. Large transactions, or high amounts of |
| 187 | # concurrency, will cause the system to fill this faster and thus |
| 188 | # make the system more disk-bound. For more details, refer |
| 189 | # https://dev.mysql.com/doc/refman/5.7/en/innodb-parameters.html#sysvar_innodb_log_buffer_size |
| 190 | iniset -sudo $my_conf mysqld innodb_log_buffer_size 256K |
| 191 | |
| 192 | # innodb_sort_buffer_size, This buffer is used for sorting when |
| 193 | # InnoDB is creating indexes. Could cause that to be slower, but |
| 194 | # only if tables are large. This is a per-connection setting. For |
| 195 | # more details, refer |
| 196 | # https://dev.mysql.com/doc/refman/5.7/en/innodb-parameters.html#sysvar_innodb_sort_buffer_size |
| 197 | iniset -sudo $my_conf mysqld innodb_sort_buffer_size 64K |
| 198 | |
| 199 | # join_buffer_size, This buffer makes table and index scans |
| 200 | # faster. So this setting could make some queries more disk |
| 201 | # bound. This is a per-connection setting. For more details refer |
| 202 | # https://dev.mysql.com/doc/refman/5.7/en/server-system-variables.html#sysvar_join_buffer_size. |
| 203 | iniset -sudo $my_conf mysqld join_buffer_size 128 |
| 204 | |
| 205 | # key_buffer_size defines the index blocks used for MyISAM tables |
| 206 | # and shared between threads. This is a server wide setting. For |
| 207 | # more details see |
| 208 | # https://dev.mysql.com/doc/refman/5.7/en/server-system-variables.html#sysvar_key_buffer_size |
| 209 | iniset -sudo $my_conf mysqld key_buffer_size 8 |
| 210 | |
| 211 | # max_heap_table_size sets the maximum amount of memory for MEMORY |
| 212 | # tables (which we don't use). The value is set to 16k, the |
| 213 | # minimum allowed. For more details, see |
| 214 | # https://dev.mysql.com/doc/refman/5.7/en/server-system-variables.html#sysvar_max_heap_table_size |
| 215 | iniset -sudo $my_conf mysqld max_heap_table_size 16K |
| 216 | |
| 217 | # net_buffer_length Each client has a buffer for incoming and |
| 218 | # outgoing data, both start with a size of net_buffer_length and |
| 219 | # can grow (in steps of 2x) upto a size of max_allowed_packet. For |
| 220 | # more details see |
| 221 | # https://dev.mysql.com/doc/refman/5.7/en/server-system-variables.html#sysvar_net_buffer_length |
| 222 | iniset -sudo $my_conf mysqld net_buffer_length 1K |
| 223 | |
| 224 | # read_buffer_size, read_rnd_buffer_size are per-thread buffer |
| 225 | # used for scans on MyISAM tables. It is a per-connection setting |
| 226 | # and so we set it to the minimum value allowable. Same for |
| 227 | # read_rnd_buffer_size. For more details refer |
| 228 | # https://dev.mysql.com/doc/refman/5.6/en/server-system-variables.html#sysvar_read_buffer_size |
| 229 | # and |
| 230 | # https://dev.mysql.com/doc/refman/5.6/en/server-system-variables.html#sysvar_read_rnd_buffer_size |
| 231 | iniset -sudo $my_conf mysqld read_buffer_size 8200 |
| 232 | iniset -sudo $my_conf mysqld read_rnd_buffer_size 8200 |
| 233 | |
| 234 | # sort_buffer_size when a sort is requested, it will be performed |
| 235 | # in memory in a buffer of this size (allocated per connection) |
| 236 | # and if the data exceeds this size it will spill to disk. The |
| 237 | # innodb and myisam variables are used in computing indices for |
| 238 | # tables using the specified storage engine. Since we don't |
| 239 | # dynamically reindex (except during upgrade) these values should |
| 240 | # never be material. Obviously performance of disk based sorts is |
| 241 | # worse than in memory sorts and therefore a high value here will |
| 242 | # improve sort performance for large data. For more details, |
| 243 | # refer: |
| 244 | # https://dev.mysql.com/doc/refman/5.7/en/server-system-variables.html#sysvar_sort_buffer_size |
| 245 | # and |
| 246 | # https://dev.mysql.com/doc/refman/5.7/en/innodb-parameters.html#sysvar_innodb_sort_buffer_size |
| 247 | # and |
| 248 | # https://dev.mysql.com/doc/refman/5.7/en/server-system-variables.html#sysvar_myisam_sort_buffer_size |
| 249 | iniset -sudo $my_conf mysqld sort_buffer_size 32K |
| 250 | iniset -sudo $my_conf mysqld innodb_sort_buffer_size 64K |
| 251 | iniset -sudo $my_conf mysqld myisam_sort_buffer_size 4K |
| 252 | |
| 253 | # thread_cache_size specifies how many internal threads to cache |
| 254 | # for use with incoming connections. We set this to 0 whic means |
| 255 | # that each connection will cause a new thread to be created. This |
| 256 | # could cause connections to take marginally longer on os'es with |
| 257 | # slow pthread_create calls. For more details, refer |
| 258 | # https://dev.mysql.com/doc/refman/5.7/en/server-system-variables.html#sysvar_thread_cache_size |
| 259 | iniset -sudo $my_conf mysqld thread_cache_size 0 |
| 260 | |
| 261 | # thread_stack is the per connection stack size, the minimum is |
| 262 | # 128k and the default is 192k on 32bit and 256k on 64bit |
| 263 | # systems. We set this to 192k. Complex queries which require |
| 264 | # recursion, stored procedures or other memory intensive |
| 265 | # operations could exhaust this and generate a very characteristic |
| 266 | # failure ("stack overflow") which is cleanly detected and the |
| 267 | # query is killed. For more details see |
| 268 | # https://dev.mysql.com/doc/refman/5.6/en/server-system-variables.html#sysvar_thread_stack |
| 269 | iniset -sudo $my_conf mysqld thread_stack 196608 |
| 270 | |
| 271 | # tmp_table_size is the maximum size of an in-memory temporary |
| 272 | # table. Temporary tables are created by MySQL as part of a |
| 273 | # multi-step query plan. The actual size of the temp table will be |
| 274 | # the lesser of tmp_table_size and max_heap_table_size. If a |
| 275 | # temporary table exceeds this size, it will be spooled to disk |
| 276 | # using the internal_tmp_disk_storage_engine (default |
| 277 | # MyISAM). Queries that often generate in-memory temporary tables |
| 278 | # include queries that have sorts, distinct, or group by |
| 279 | # operations, also queries that perform IN joins. For more details |
| 280 | # see |
| 281 | # https://dev.mysql.com/doc/refman/5.7/en/server-system-variables.html#sysvar_tmp_table_size |
| 282 | iniset -sudo $my_conf mysqld tmp_table_size 1K |
| 283 | |
Jeremy Stanley | c4f4734 | 2014-01-25 01:10:31 +0000 | [diff] [blame] | 284 | if [[ "$DATABASE_QUERY_LOGGING" == "True" ]]; then |
| 285 | echo_summary "Enabling MySQL query logging" |
Attila Fazekas | 1f316be | 2015-01-26 16:39:57 +0100 | [diff] [blame] | 286 | if is_fedora; then |
Attila Fazekas | 3b53aeb | 2014-04-30 11:57:22 +0200 | [diff] [blame] | 287 | slow_log=/var/log/mariadb/mariadb-slow.log |
| 288 | else |
| 289 | slow_log=/var/log/mysql/mysql-slow.log |
| 290 | fi |
Ralf Haferkamp | 0526bb8 | 2014-04-03 08:27:33 +0200 | [diff] [blame] | 291 | sudo sed -e '/log.slow.queries/d' \ |
| 292 | -e '/long.query.time/d' \ |
| 293 | -e '/log.queries.not.using.indexes/d' \ |
Dean Troyer | 3ef23bc | 2014-07-25 14:56:22 -0500 | [diff] [blame] | 294 | -i $my_conf |
Monty Taylor | 7c73e8d | 2013-01-07 08:17:01 +0000 | [diff] [blame] | 295 | |
Ralf Haferkamp | 0526bb8 | 2014-04-03 08:27:33 +0200 | [diff] [blame] | 296 | # Turn on slow query log, log all queries (any query taking longer than |
| 297 | # 0 seconds) and log all non-indexed queries |
Ian Wienand | 9c0b9f3 | 2015-07-22 06:08:09 +1000 | [diff] [blame] | 298 | iniset -sudo $my_conf mysqld slow-query-log 1 |
| 299 | iniset -sudo $my_conf mysqld slow-query-log-file $slow_log |
| 300 | iniset -sudo $my_conf mysqld long-query-time 0 |
| 301 | iniset -sudo $my_conf mysqld log-queries-not-using-indexes 1 |
Jeremy Stanley | c4f4734 | 2014-01-25 01:10:31 +0000 | [diff] [blame] | 302 | fi |
Monty Taylor | 7c73e8d | 2013-01-07 08:17:01 +0000 | [diff] [blame] | 303 | |
Dean Troyer | 3ef23bc | 2014-07-25 14:56:22 -0500 | [diff] [blame] | 304 | restart_service $mysql |
Terry Wilson | 428af5a | 2012-11-01 16:12:39 -0400 | [diff] [blame] | 305 | } |
| 306 | |
| 307 | function install_database_mysql { |
Vincent Untz | c18b965 | 2012-12-04 12:36:34 +0100 | [diff] [blame] | 308 | if is_ubuntu; then |
Terry Wilson | 428af5a | 2012-11-01 16:12:39 -0400 | [diff] [blame] | 309 | # Seed configuration with mysql password so that apt-get install doesn't |
| 310 | # prompt us for a password upon install. |
Bob Ball | 9033343 | 2015-01-19 10:56:42 +0000 | [diff] [blame] | 311 | sudo debconf-set-selections <<MYSQL_PRESEED |
| 312 | mysql-server mysql-server/root_password password $DATABASE_PASSWORD |
| 313 | mysql-server mysql-server/root_password_again password $DATABASE_PASSWORD |
| 314 | mysql-server mysql-server/start_on_boot boolean true |
Terry Wilson | 428af5a | 2012-11-01 16:12:39 -0400 | [diff] [blame] | 315 | MYSQL_PRESEED |
| 316 | fi |
| 317 | |
| 318 | # while ``.my.cnf`` is not needed for OpenStack to function, it is useful |
| 319 | # as it allows you to access the mysql databases via ``mysql nova`` instead |
| 320 | # of having to specify the username/password each time. |
| 321 | if [[ ! -e $HOME/.my.cnf ]]; then |
| 322 | cat <<EOF >$HOME/.my.cnf |
| 323 | [client] |
| 324 | user=$DATABASE_USER |
| 325 | password=$DATABASE_PASSWORD |
Johan Pas | 199d857 | 2015-11-17 00:56:25 +0100 | [diff] [blame] | 326 | host=$MYSQL_HOST |
Terry Wilson | 428af5a | 2012-11-01 16:12:39 -0400 | [diff] [blame] | 327 | EOF |
| 328 | chmod 0600 $HOME/.my.cnf |
| 329 | fi |
| 330 | # Install mysql-server |
Wiekus Beukes | ec47bc1 | 2015-03-19 08:20:38 -0700 | [diff] [blame] | 331 | if is_suse || is_oraclelinux; then |
Vincent Untz | 623a0a5 | 2013-04-11 08:41:27 +0200 | [diff] [blame] | 332 | if ! is_package_installed mariadb; then |
| 333 | install_package mysql-community-server |
| 334 | fi |
Wiekus Beukes | ec47bc1 | 2015-03-19 08:20:38 -0700 | [diff] [blame] | 335 | elif is_fedora; then |
| 336 | install_package mariadb-server |
Zhang Jinnan | 4d8c03a | 2015-08-20 10:00:20 -0400 | [diff] [blame] | 337 | sudo systemctl enable mariadb |
Wiekus Beukes | ec47bc1 | 2015-03-19 08:20:38 -0700 | [diff] [blame] | 338 | elif is_ubuntu; then |
| 339 | install_package mysql-server |
Vincent Untz | ca5c471 | 2012-11-21 17:45:49 +0100 | [diff] [blame] | 340 | else |
Vincent Untz | 00011c0 | 2012-12-06 09:56:32 +0100 | [diff] [blame] | 341 | exit_distro_not_supported "mysql installation" |
Vincent Untz | ca5c471 | 2012-11-21 17:45:49 +0100 | [diff] [blame] | 342 | fi |
Dean Troyer | 5686dbc | 2015-03-09 14:27:51 -0500 | [diff] [blame] | 343 | } |
Dean Troyer | b1d8e8e | 2015-02-16 13:58:35 -0600 | [diff] [blame] | 344 | |
Dean Troyer | 5686dbc | 2015-03-09 14:27:51 -0500 | [diff] [blame] | 345 | function install_database_python_mysql { |
Dean Troyer | b1d8e8e | 2015-02-16 13:58:35 -0600 | [diff] [blame] | 346 | # Install Python client module |
Sean Dague | 3742199 | 2015-05-20 06:37:11 -0700 | [diff] [blame] | 347 | pip_install_gr $MYSQL_DRIVER |
| 348 | if [[ "$MYSQL_DRIVER" == "MySQL-python" ]]; then |
| 349 | ADDITIONAL_VENV_PACKAGES+=",MySQL-python" |
Julien Danjou | 0f63eb3 | 2015-06-12 09:05:12 +0200 | [diff] [blame] | 350 | elif [[ "$MYSQL_DRIVER" == "PyMySQL" ]]; then |
| 351 | ADDITIONAL_VENV_PACKAGES+=",PyMySQL" |
Sean Dague | 3742199 | 2015-05-20 06:37:11 -0700 | [diff] [blame] | 352 | fi |
Terry Wilson | 428af5a | 2012-11-01 16:12:39 -0400 | [diff] [blame] | 353 | } |
| 354 | |
| 355 | function database_connection_url_mysql { |
Attila Fazekas | 7e79d91 | 2013-03-03 12:23:04 +0100 | [diff] [blame] | 356 | local db=$1 |
| 357 | echo "$BASE_SQL_CONN/$db?charset=utf8" |
Terry Wilson | 428af5a | 2012-11-01 16:12:39 -0400 | [diff] [blame] | 358 | } |
| 359 | |
Dean Troyer | cc6b443 | 2013-04-08 15:38:03 -0500 | [diff] [blame] | 360 | |
Terry Wilson | 428af5a | 2012-11-01 16:12:39 -0400 | [diff] [blame] | 361 | # Restore xtrace |
Ian Wienand | 523f488 | 2015-10-13 11:03:03 +1100 | [diff] [blame] | 362 | $_XTRACE_DB_MYSQL |
Sean Dague | 584d90e | 2013-03-29 14:34:53 -0400 | [diff] [blame] | 363 | |
| 364 | # Local variables: |
| 365 | # mode: shell-script |
| 366 | # End: |