Wiki source code of MySQL Installation

Version 75.1 by Thomas Mortagne on 2022/10/31

Show last authors
1 {{box cssClass="floatinginfobox" title="**Contents**"}}
2 {{toc/}}
3 {{/box}}
4
5 = Compatibility Considerations =
6
7 See [[Database support strategy>>dev:Community.DatabaseSupportStrategy]] for the supported versions.
8
9 == MyISAM storage engine ==
10
11 MyISAM (the default storage engine for MySQL until release 5.5.5 in 2010) does not support transactions. If there is an error while data is being saved to the database, XWiki will attempt to roll back the transaction to its previous known good state. If you use MyISAM, it will do nothing, leaving the database in whatever state it was in when the error occurred.
12
13 {{warning}}
14 If you use MySQL with any engine that does not support transactions, you will most likely corrupt your database.** We highly recommend using a storage engine such as InnoDB which supports transactions.**
15 {{/warning}}
16
17 == MySQL versions older than 5.0 ==
18
19 XWiki does not fully work with MySQL versions 4.x or lower, due to several limitations of the way the SQL standards are implemented in MySQL, limited support for non-latin1 encodings, the flaky integration of Hibernate and MySQL 4, and other things. Most parts of the application work fine, but there are some parts that cannot be easily fixed, so if you must use MySQL 4.x, you're doing it on your own. MySQL 4 is pretty old and buggy, so we recommend upgrading.
20
21 == MySQL versions older than 5.7 and utf8mb4 ==
22
23 If you use utf8mb4 encoding, you won't be able to use a version of MySQL older than 5.7 out of the box because of a limitation in the default maximum size of the keys and the default row format.
24
25 == JDBC Driver Version ==
26
27 * It's recommended to use the latest version of the MySQL JDBC driver (8.x) if you're using MySQL 5.7+.
28 * If you're using XWiki < 13.3RC1, you should not use version 8.0.23 of the MySQL JDBC driver since it [[causes a problem with the Liquibase version used in XWiki>>https://jira.xwiki.org/browse/XWIKI-18515]].
29
30 = Installation Steps =
31
32 Follow these instructions:
33
34 * Download and install [[MySQL>>http://www.mysql.com/]] 5.7 or greater.
35 * Start the MySQL server. You can do that in several ways. For example use {{code language="shell"}}mysqld --console{{/code}}
36 * Create the wiki database. You can use the name you want for the database, but you will have to set the hibernate configuration file and ##xwiki.cfg## file accordingly.(((
37 You can create the database in several ways. For example use:
38
39 {{code language="shell"}}
40 mysql -u root -e "create database xwiki default character set utf8mb4 collate utf8mb4_bin"
41 {{/code}}
42 )))
43 * Create the ##xwiki## user with password ##xwiki##(((
44 {{code language="shell"}}
45 mysql -u root -e "CREATE USER 'xwiki'@'localhost' IDENTIFIED BY 'xwiki'";
46 {{/code}}
47 )))
48 * Give privileges to the ##xwiki## user for accessing and creating databases (for the multi wiki support). Specifically the ##xwiki## users needs permissions to be able to execute {{code language="sql"}}CREATE DATABASE{{/code}}, {{code language="sql"}}DROP SCHEMA{{/code}}, and then all CRUD operations on tables. Note that the command below should be tuned to be more restrictive as granting all permissions is not required:(((
49 {{code language="shell"}}
50 mysql -u root -e "grant all privileges on *.* to xwiki@localhost"
51 {{/code}}
52 )))
53 * If the above command fails with a password-does-not-meet-requirements error, uninstall the MySQL password_validate plugin or pick a more complex password and update the password used by default in ##hibernate.cfg.xml##:(((
54 {{code language="shell"}}
55 mysql -u root -p -e "uninstall plugin validate_password;"
56 {{/code}}
57 )))
58 * Please make sure that the DNS-name "localhost" is defined in your hosts-file (i.e. ##/etc/hosts##)
59 * You need to have the MySQL JDBC Driver JAR (named ##mysql-connector-java*.jar##) installed in XWiki's WAR file. If this file isn't present in XWiki's ##WEB-INF/lib## directory you'll need to download it and copy it there. You can download it from the [[MySQL Connector/J Driver page>>http://www.mysql.com/downloads/connector/j/]] or directly from the [[Maven Central Repository>>https://repo1.maven.org/maven2/mysql/mysql-connector-java/]].(((
60 {{warning}}
61 You need the 5.x version or higher. The 3.x version doesn't handle Boolean data correctly and will either throw errors or will make all documents hidden by default.
62 {{/warning}}
63 )))
64 * Now you need to tell XWiki to use MySQL. To do this, edit the ##WEB-INF/hibernate.cfg.xml## file where you have expanded the XWiki WAR file and replace the matching properties with the following ones:(((
65 {{code language="xml"}}
66 <property name="connection.url">jdbc:mysql://localhost/xwiki</property>
67 <property name="connection.username">xwiki</property>
68 <property name="connection.password">xwiki</property>
69 <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
70 <property name="connection.useUnicode">true</property>
71 <property name="connection.characterEncoding">UTF-8</property>
72 {{/code}}
73
74 {{info}}
75 * By default MySQL only accepts packets that are smaller than 1MB. If you get the "Packet for query is too large (max_allowed_packet)" error then see the [[Packet too large error page>>http://dev.mysql.com/doc/refman/5.0/en/packet-too-large.html]]. For example to increase the packet size to 32M you could start the MySQL server with {{code language='shell'}}mysqld --console --max_allowed_packet=32M{{/code}} or you can modify directly the ##my.cnf## configuration file to set this value permanently.
76 * If an empty XWiki starts with no errors, but you are unable to upload the default set of pages (XAR file) try to increase the ##max_allowed_packet## parameter as shown above.
77 {{/info}}
78 )))
79
80 = Indexes =
81
82 See [[Database Administration>>Documentation.AdminGuide.Performances.Database Administration.WebHome]].
83
84 {{code language="mysql"}}
85 // Required
86 create index xwl_value on xwikilargestrings (xwl_value(50));
87 create index xwd_parent on xwikidoc (xwd_parent(50));
88 create index xwd_class_xml on xwikidoc (xwd_class_xml(20));
89 create index xda_docid1 on xwikiattrecyclebin (xda_docid);
90 create index solr_iterate_all_documents on xwikidoc (XWD_WEB(500), XWD_NAME(253), XWD_LANGUAGE(5), XWD_VERSION(10));
91 // Only required if you use stats (feature is off by default)
92 create index xws_number on xwikistatsdoc (XWS_NUMBER);
93 create index xws_classname on xwikistatsdoc (XWS_CLASSNAME);
94 create index xwr_number on xwikistatsreferer (XWR_NUMBER);
95 create index xwr_classname on xwikistatsreferer (XWR_CLASSNAME);
96 create index xwr_referer on xwikistatsreferer (XWR_REFERER(50));
97 create index xwv_user_agent on xwikistatsvisit (XWV_USER_AGENT(255));
98 create index xwv_cookie on xwikistatsvisit (XWV_COOKIE(255));
99 create index xwv_classname on xwikistatsvisit (XWV_CLASSNAME);
100 create index xwv_number on xwikistatsvisit (XWV_NUMBER);
101 {{/code}}
102
103 {{info}}
104 Note to XWiki developers: The following indexes could be created automatically though since they're less than 255 characters and thus should be added in a future version of XWiki so that they don't need to be created manually:
105
106 {{code language="mysql"}}
107 create index xws_number on xwikistatsdoc (XWS_NUMBER);
108 create index xws_classname on xwikistatsdoc (XWS_CLASSNAME);
109 create index xwr_number on xwikistatsreferer (XWR_NUMBER);
110 create index xwr_classname on xwikistatsreferer (XWR_CLASSNAME);
111 create index xwv_classname on xwikistatsvisit (XWV_CLASSNAME);
112 create index xwv_number on xwikistatsvisit (XWV_NUMBER);
113 create index xda_docid1 on xwikiattrecyclebin (xda_docid);
114 {{/code}}
115 {{/info}}
116
117 = Tips =
118
119 == MySQL 8 ==
120
121 * If you're using MySQL 8+ you'll need to configure MySQL with native password: ##default-authentication-plugin=mysql_native_password##.
122 * You'll also be able to switch from ##com.mysql.jdbc.Driver## to ##com.mysql.cj.jdbc.Driver## JDBC driver (since the previous driver class is now deprecated).
123 * If you get the following error then you'll need to force the timezone to use either by setting it in:(((
124 * The MySQL conf file on the server
125 * In the XWiki ##hibernate.cfg.xml## file in the ##hibernate.connection.serverTimezone## property (e.g. ##<property name="hibernate.connection.serverTimezone">Europe/Berlin</property>##).
126 * In the XWiki ##hibernate.cfg.xml## file inside the JDBC URL string as in ##jdbc:mysql:~/~/localhost:3306/myschema?serverTimezone=UTC##
127
128 {{code language="none"}}
129 The server timezone value 'CDT' is unrecognized or represents more than one timezone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc timezone value if you want to utilize timezone support.
130 {{/code}}
131
132 For more details see [[this explanation post>>https://stackoverflow.com/a/54256150/153102]].
133 )))
134
135 == Convert a database from latin1 (or collation utf8_ci) to utf8mb4/utf8mb4_bin ==
136
137 {{code language="shell"}}
138 #!/bin/bash
139
140 db=xwiki
141 to_character_set=utf8mb4
142 to_collation=utf8mb4_bin
143
144 mysql_cmd="mysql -u root"
145
146 $mysql_cmd -e "ALTER DATABASE $db CHARACTER SET $to_character_set COLLATE $to_collation;"
147
148 TBL_LIST=$($mysql_cmd -N -s -r -e "use $db;show tables;")
149
150 echo "Temporarily disable all the foreign keys"
151
152 $MYSQL_COMMAND -e "SET FOREIGN_KEY_CHECKS=0;"
153 for tbl_name in $TBL_LIST;
154 do
155 $mysql_cmd -e "alter table $db.$tbl_name convert to character set $to_character_set collate $to_collation;"
156 done
157
158 echo "Turn foreign keys back on"
159
160 $MYSQL_COMMAND -e "SET FOREIGN_KEY_CHECKS=1;"
161
162 echo "Here the result of the operation:"
163 $mysql_cmd -e "USE $db;SELECT TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME, COLUMN_NAME, COLLATION_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA=DATABASE();"
164 {{/code}}
165
166 (% class="box infomessage" %)
167 (((
168 In case the above script fails to convert some rows with "ERROR 1833 (HY000) at line 1: Cannot change column 'columnname': used in a foreign key constraint 'FK2bj2ghquiq79toomkvugw7iie' of table 'xwiki.tablename', you can drop the foreign keys, convert the columns and then restart xWiki. Hibernate will re-create the dropped indexes automatically.
169 )))
170
171 (% class="box infomessage" %)
172 (((
173 In case the above script fails with "ERROR 1118 (42000) at line 1: Row size too large. The maximum row size for the used table type, not counting BLOBs, is 65535. This includes storage overhead, check the manual. You have to change some columns to TEXT or BLOBs
174 xwikistatsvisit", you can use the following SQL statements to change tables column types to LONGTEXT to be able to convert the tables to utf8mb4.
175 )))
176
177 {{code}}
178 ALTER TABLE activitystream_events MODIFY ase_url LONGTEXT, MODIFY ase_title LONGTEXT, MODIFY ase_body LONGTEXT, MODIFY ase_param1 LONGTEXT, MODIFY ase_param2 LONGTEXT, MODIFY ase_param3 LONGTEXT, MODIFY ase_param4 LONGTEXT, MODIFY ase_param5 LONGTEXT;
179 ALTER TABLE xwikistatsreferer MODIFY XWR_REFERER LONGTEXT;
180 ALTER TABLE xwikistatsvisit MODIFY XWV_USER_AGENT LONGTEXT, MODIFY XWV_COOKIE LONGTEXT;
181 ALTER TABLE xwikipreferences MODIFY XWP_LEFT_PANELS LONGTEXT, MODIFY XWP_RIGHT_PANELS LONGTEXT, MODIFY XWP_DOCUMENT_BUNDLES LONGTEXT;
182 {{/code}}
183
184 You can also look at [[this snippet to perform this conversion inside XWiki>>snippets:Extension.Migrate MySQL databases to utf8mb4]].
185
186 == Convert from MyISAM to InnoDB ==
187
188 {{code language="shell"}}
189 #!/bin/bash
190
191 MYSQL_COMMAND=mysql
192 TO_ENGINE=INNODB
193
194 DATABASES=$(mysql -N -s -r -e 'show databases'|grep -v ^information_schema$|grep -v ^mysql$)
195
196 for db in $DATABASES
197 do
198
199 echo "Working on database $db..."
200 echo ""
201
202 TABLES=$(mysql -N -s -r -e "show tables from $db;")
203
204 for tb in $TABLES
205 do
206
207 $MYSQL_COMMAND -e "ALTER TABLE $db.$tb ENGINE = $TO_ENGINE;"
208
209 done
210
211 $MYSQL_COMMAND -e "SELECT table_name,Engine,table_collation FROM information_schema.tables WHERE table_schema = DATABASE();"
212
213 echo ""
214 echo ""
215
216 done
217 {{/code}}
218
219 = Troubleshooting =
220
221 == Unable to login to MySQL Console ==
222
223 When running {{code language="shell"}}mysql -u root -e "create database xwiki default character set utf8mb4{{/code}} you may get a {{code}}ERROR 1045 (28000): Access denied for user 'xwiki'@'localhost' (using password: YES){{/code}} error.
224 This means that you have a password set for the MySQL root user, but you are not specifying it in the console command. You must also use the //-p// parameter. Using this you will be prompted to enter the password and be allowed to login to the MySQL console and create the database.
225
226 == Can't create test file ==
227
228 When running ##mysqld ~-~-console## you may get the following (especially if you're on a Mac):
229
230 {{code language="none"}}
231 071111 17:20:53 [Warning] Can't create test file /usr/local/mysql-5.0.45-osx10.4-i686/data/Vincent.lower-test
232 071111 17:20:53 [Warning] Can't create test file /usr/local/mysql-5.0.45-osx10.4-i686/data/Vincent.lower-test
233 mysqld: Can't change dir to '/usr/local/mysql-5.0.45-osx10.4-i686/data/' (Errcode: 13)
234 071111 17:20:53 [ERROR] Aborting
235 {{/code}}
236
237 To start MySQL run the following command instead:
238
239 {{code}}
240 sudo /usr/local/mysql/bin/mysqld_safe --user=mysql
241 {{/code}}
242
243 == Data Truncation Error ==
244
245 If you receive an Exception like the following while installing/upgrading XWiki, chances are that you are using an outdated version of MySQLConnectorJ.
246
247 {{code language="none"}}
248 Caused by: java.sql.BatchUpdateException: Data truncation: Out of
249 range value adjusted for column 'XWD_HIDDEN' at row 1
250 at com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:894)
251 at org.apache.commons.dbcp.DelegatingStatement.executeBatch(DelegatingStatement.java:294)
252 at org.apache.commons.dbcp.DelegatingStatement.executeBatch(DelegatingStatement.java:294)
253 at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)
254 at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:246)
255 {{/code}}
256
257 On Linux, mysql-connector-java-3.x has proven **not** to work due to a bug in the handling of UTF-8 and lack of support for Boolean types.
258
259 Upgrading to the latest version of MySQLConnectorJ should solve such an error in most of the cases.
260
261 == HTTP 500 Error ==
262
263 {{code language="none"}}
264 HTTP Status 500 -
265
266 type Exception report
267
268 message
269
270 descriptionThe server encountered an internal error () that prevented it from fulfilling this request.
271
272 exception
273
274 javax.servlet.ServletException: com.xpn.xwiki.XWikiException: Error number 3 in 0: Could not initialize main XWiki context
275 Wrapped Exception: Error number 3001 in 3: Cannot load class com.xpn.xwiki.store.migration.hibernate.XWikiHibernateMigrationManager from param xwiki.store.migration.manager.class
276 Wrapped Exception: Error number 0 in 3: Exception while hibernate execute
277 Wrapped Exception: Could not create a DBCP pool. There is an error in the hibernate configuration file, please review it.
278
279 root cause
280
281 com.xpn.xwiki.XWikiException: Error number 3 in 0: Could not initialize main XWiki context
282 Wrapped Exception: Error number 3001 in 3: Cannot load class com.xpn.xwiki.store.migration.hibernate.XWikiHibernateMigrationManager from param xwiki.store.migration.manager.class
283 Wrapped Exception: Error number 0 in 3: Exception while hibernate execute
284 Wrapped Exception: Could not create a DBCP pool. There is an error in the hibernate configuration file, please review it.
285 {{/code}}
286
287 In this case, try to disable **skip-networking** in MySQL *.ini file. Thanks a lot //M Rawash// (see his comment below).
288
289 == Unknown database 'xwiki' ==
290
291 If you get the following error:
292
293 {{code language="none"}}
294 Caused by: class com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown database 'xwiki'
295 at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
296 at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
297 at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
298 at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
299 at com.mysql.jdbc.Util.handleNewInstance(Util.java:408)
300 at com.mysql.jdbc.Util.getInstance(Util.java:383)
301 at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1062)
302 at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4226)
303 at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4158)
304 at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2615)
305 at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2776)
306 at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2834)
307 at com.mysql.jdbc.ConnectionImpl.setCatalog(ConnectionImpl.java:5456)
308 at org.apache.commons.dbcp.DelegatingConnection.setCatalog(DelegatingConnection.java:374)
309 at org.apache.commons.dbcp.DelegatingConnection.setCatalog(DelegatingConnection.java:374)
310 at org.apache.commons.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.setCatalog(PoolingDataSource.java:333)
311 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
312 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
313 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
314 at java.lang.reflect.Method.invoke(Method.java:606)
315 at org.hibernate.jdbc.BorrowedConnectionProxy.invoke(BorrowedConnectionProxy.java:74)
316 at com.sun.proxy.$Proxy47.setCatalog(Unknown Source)
317 at com.xpn.xwiki.store.XWikiHibernateBaseStore.setDatabase(XWikiHibernateBaseStore.java:729)
318 at com.xpn.xwiki.store.XWikiHibernateBaseStore.beginTransaction(XWikiHibernateBaseStore.java:911)
319 at com.xpn.xwiki.store.XWikiHibernateBaseStore.beginTransaction(XWikiHibernateBaseStore.java:843)
320 at com.xpn.xwiki.store.XWikiHibernateStore.loadXWikiDoc(XWikiHibernateStore.java:830)
321 ...
322 {{/code}}
323
324 It means that XWiki could connect to your database but there's no ##xwiki## schema available there. This is the default name of the schema XWiki is looking for, for the main wiki database.
325
326 It probably means you've created a database named other than ##xwiki## (for example you might have created a database named ##abcd## and set the following connection URL in your ##hibernate.cfg## file: {{code language="none"}}<property name="connection.url">jdbc:mysql://localhost/abcd</property>{{/code}}).
327
328 If this is the case [[you need to tell XWiki that you're using a different schema by setting the ##xwiki.db## configuration property>>platform:AdminGuide.Configuration#HConfigurethenamesofdatabaseschemas]].
329
330 == MySQLSyntaxErrorException: Row size too large (> 8126) ==
331
332 if you get the following error:
333
334 {{code language="none"}}
335 MySQLSyntaxErrorException: Row size too large (> 8126).
336 Changing some columns to TEXT or BLOB or using ROW_FORMAT=DYNAMIC or ROW_FORMAT=COMPRESSED may help.
337 In current row format, BLOB prefix of 768 bytes is stored inline.
338 {{/code}}
339
340 When you are using a MySQL Server 5.6.20 you can get a "row size too large error."
341 In the release notes, it is explained that a innodb_log_file_size which is too small will trigger a "Row size too large error."
342
343 You can solve the problem by changing the innodb_log_file_size in the my.ini text file.
344 Find more details in the link below.
345 http://dev.mysql.com/doc/relnotes/mysql/5.6/en/news-5-6-20.html

Get Connected