After the installation is completed, you can start/stop MySQL using the following commands, which vary from different platforms and installation methods. mysqld is the mysql server process. All the startup methods invoke the mysqld script.
Starting or Stopping MySQL 8
How to do it...
Let's look at it in detail. Along with the starting and stopping, we will also learn something about checking the status of the server. Let's see how.
Starting the MySQL 8.0 server
You can start the server with the following commands:
- Using service:
shell> sudo service mysql start
- Using init.d:
shell> sudo /etc/init.d/mysql start
- If you do not find the startup script (when you are doing binary installation), you can copy from the location where you untarred.
shell> sudo cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
- If your installation includes systemd support:
shell> sudo systemctl start mysqld
- If the systemd support is not there, MySQL can be started using mysqld_safe. mysqld_safe is the launcher script for mysqld that safeguards the mysqld process. If mysqld is killed, mysqld_safe attempts to start the process again:
shell> sudo mysqld_safe --user=mysql &
After start,
- The server is initialized.
- The SSL certificate and key files are generated in the data directory.
- The validate_password plugin is installed and enabled.
- A superuser account, root'@'localhost, is created. A password for the superuser is set and stored in the error log file (not for binary installation). To reveal it, use the following command:
shell> sudo grep "temporary password" /var/log/mysqld.log
2017-12-02T07:23:20.915827Z 5 [Note] A temporary password is generated for root@localhost: bkvotsG:h6jD
You can connect to MySQL using that temporary password.
shell> mysql -u root -pbkvotsG:h6jD
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 8.0.3-rc-log
Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
- Change the root password as soon as possible by logging in with the generated temporary password and setting a custom password for the superuser account:
# You will be prompted for a password, enter the one you got from the previous step
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'NewPass4!';
Query OK, 0 rows affected (0.01 sec)
# password should contain at least one Upper case letter, one lowercase letter, one digit, and one special character, and that the total password length is at least 8 characters
Stopping the MySQL 8.0 server
Stopping MySQL and checking the status are similar to starting it, except for the change of one word:
- Using service:
shell> sudo service mysqld stop
Redirecting to /bin/systemctl stop mysqld.service
- Using init.d:
shell> sudo /etc/init.d/mysql stop
[ ok ] Stopping mysql (via systemctl): mysql.service.
- If your installation includes the systemd support (refer to the Managing MySQL Server with systemd section):
shell> sudo systemctl stop mysqld
- Using mysqladmin:
shell> mysqladmin -u root -p shutdown
Checking the status of the MySQL 8.0 server
- Using service:
shell> sudo systemctl status mysqld
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Drop-In: /etc/systemd/system/mysqld.service.d
└─override.conf
Active: active (running) since Sat 2017-12-02 07:33:53 UTC; 14s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 10472 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
Process: 10451 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
Main PID: 10477 (mysqld)
CGroup: /system.slice/mysqld.service
└─10477 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid --general_log=1
Dec 02 07:33:51 centos7 systemd[1]: Starting MySQL Server...
Dec 02 07:33:53 centos7 systemd[1]: Started MySQL Server.
- Using init.d:
shell> sudo /etc/init.d/mysql status
● mysql.service - LSB: start and stop MySQL
Loaded: loaded (/etc/init.d/mysql; bad; vendor preset: enabled)
Active: inactive (dead)
Docs: man:systemd-sysv-generator(8)
Dec 02 06:01:00 ubuntu systemd[1]: Starting LSB: start and stop MySQL...
Dec 02 06:01:00 ubuntu mysql[20334]: Starting MySQL
Dec 02 06:01:00 ubuntu mysql[20334]: *
Dec 02 06:01:00 ubuntu systemd[1]: Started LSB: start and stop MySQL.
Dec 02 06:01:00 ubuntu mysql[20334]: 2017-12-02T06:01:00.969284Z mysqld_safe A mysqld process already exists
Dec 02 06:01:55 ubuntu systemd[1]: Stopping LSB: start and stop MySQL...
Dec 02 06:01:55 ubuntu mysql[20445]: Shutting down MySQL
Dec 02 06:01:57 ubuntu mysql[20445]: .. *
Dec 02 06:01:57 ubuntu systemd[1]: Stopped LSB: start and stop MySQL.
Dec 02 07:26:33 ubuntu systemd[1]: Stopped LSB: start and stop MySQL.
- If your installation includes the systemd support (refer to the Managing MySQL Server with systemd section):
shell> sudo systemctl status mysqld