Difference between revisions of "MySQL"

From Dogtag
Jump to: navigation, search
m (References)
m (Installation)
Line 5: Line 5:
 
<pre>
 
<pre>
 
$ dnf install community-mysql
 
$ dnf install community-mysql
 +
</pre>
 +
 +
To install MySQL server:
 +
 +
<pre>
 +
$ dnf install community-mysql-server
 +
$ systemctl start mysqld
 +
$ systemctl enable mysqld
 +
</pre>
 +
 +
Get root's temporary password:
 +
 +
<pre>
 +
$ grep 'temporary password' /var/log/mysqld.log
 +
</pre>
 +
 +
Initialize MySQL server:
 +
 +
<pre>
 +
$ mysql_secure_installation
 
</pre>
 
</pre>
  

Revision as of 04:05, 20 September 2022

Installation

To install MySQL client:

$ dnf install community-mysql

To install MySQL server:

$ dnf install community-mysql-server
$ systemctl start mysqld
$ systemctl enable mysqld

Get root's temporary password:

$ grep 'temporary password' /var/log/mysqld.log

Initialize MySQL server:

$ mysql_secure_installation

Backup & Restore

To backup a database, first lock the database:

$ mysql -h <hostname> -P <port> -u <username> --password=<password> <database>
mysql> flush tables with read lock;
mysql> set global read_only = ON;
mysql> exit;

Then backup the database:

$ mysqldump -h <hostname> -P <port> -u <username> --password=<password> <database> > database.sql

Then unlock the database:

$ mysql -h <hostname> -P <port> -u <username> --password=<password> <database>
mysql> set global read_only = OFF;
mysql> unlock tables;
mysql> exit;

To restore database:

$ mysql -h <hostname> -P <port> -u <username> --password=<password> <database> < database.sql

References