Convert database sql lite to mysql in nextcloud

If you using SQL lite for nextcloud You can convert a SQLite database to a better performing MySQL, MariaDB or PostgreSQL database with the Nextcloud command line tool. SQLite is good for testing and simple single-user Nextcloud servers, but it does not scale for multiple-user production users.

Firts we need install mysql or mariaDB (readmore)

Then we need creat new user and database for nextcloud.

Example new user and database:

mysql user: ucloud,

pass: ABC123

databse name: nextcloud

In Nextcloud root folder call: 

php occ db:convert-type [options] type username hostname database

Example:

php occ db:convert-type --password ABC123 --all-apps mysql ucloud 127.0.0.1 nextcloud

In fact nextcloud permit user www-data so that need sudo user www-data:

sudo -u www-data php occ db:convert-type –password ABC123 –all-apps mysql pi 127.0.0.1 nextcloud

If you get a error: not found driver,.. you need install php-mysql Example in php 7.3

sudo apt install php7.3-mysql

You should restart apache and mysql service:

sudo systemctl restart apache2.service sudo systemctl restart mysql.service

then run cml again:

sudo -u www-data php occ db:convert-type --password ABC123 --all-apps mysql pi 127.0.0.1 nextcloud

Result sample:

Creating schema in new database
oc_accounts
 5/5 [============================] 100%oc_activity
chunked query, 50 chunks
 49794/49794 [============================] 100%oc_activity_mq
 1/1 [============================] 100%oc_addressbookchanges
 31/31 [============================] 100%oc_addressbooks
 6/6 [============================] 100%oc_appconfig
 144/144 [============================] 100%oc_audioplayer_albums
 0 [>---------------------------]oc_audioplayer_artists
 0 [>---------------------------]oc_audioplayer_genre
 0 [>---------------------------]oc_audioplayer_playlist_tracks
 0 [>---------------------------]oc_audioplayer_playlists
 0 [>---------------------------]oc_audioplayer_stats
 0 [>---------------------------]oc_audioplayer_streams
 0 [>---------------------------]oc_audioplayer_tracks
 0 [>---------------------------]oc_authtoken
 140/140 [============================] 100%oc_bruteforce_attempts
 110/110 [============================] 100%oc_calendar_invitations
 0 [>---------------------------]oc_calendar_reminders
 0 [>---------------------------]oc_calendar_resources
 0 [>---------------------------]oc_calendar_resources_md
 0 [>---------------------------]oc_calendar_rooms
 0 [>---------------------------]oc_calendar_rooms_md
 0 [>---------------------------]oc_calendarchanges
 0 [>---------------------------]oc_calendarobjects
 0 [>---------------------------]oc_calendarobjects_props
 0 [>---------------------------]oc_calendars
 6/6 [============================] 100%oc_calendarsubscriptions
 0 [>---------------------------]oc_cards
 5/5 [============================] 100%oc_cards_properties
 24/24 [============================] 100%oc_collres_accesscache
 0 [>---------------------------]oc_collres_collections
 0 [>---------------------------]oc_collres_resources
 0 [>---------------------------]oc_comments
 39/55 [===================>--------] 70%

This progress about 15-20 minutes depend on quantity of record in your old database.

Maybe have  An exception occurred while executing old record to new database but not problem:

An exception occurred while executing ‘INSERT INTO `oc_comments` (`id`, `children_count`, `actor_type`, `actor_i
d`, `message`, `verb`, `creation_timestamp`, `latest_child_timestamp`, `object_type`, `object_id`, `parent_id`,
`topmost_parent_id`) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)’ with params [“39”, “0”, “users”, “huonglt”, “\u
d83d\ude06”, “comment”, “2020-02-19 14:45:58”, null, “chat”, “2”, “0”, “0”]:

SQLSTATE[22007]: Invalid datetime format: 1366 Incorrect string value: ‘\xF0\x9F\x98\x86’ for column `nextcloud`
.`oc_comments`.`message` at row 1

the convert progress complete, nextcloud auto off maintain mode. Enjoy!

Whatch video Convert database sql lite to mysql in nextcloud in youtube

Giới thiệu honest 237 bài viết
Mình lập blog này với mục đích lưu lại + chia sẻ các các kiến thức mình đã biết hoặc đang tìm hiểu. Cơ bản giúp ích cho mình :) Nhưng hy vọng sẽ mang lại sự khởi đầu thuận lợi cho người mới bắt đầu!