📌 Download : https://dev.mysql.com/downloads/mysql/
# groupadd dba
# useradd -g dba mysql
# mkdir -p /mysql/data
# mkdir -p /mysql/log
# chown -R mysql.dba /mysql
# tar -xf mysql-8.0.23-linux-glibc2.12-x86_64.tar.xz -C /usr/local
# cd /usr/local
# mv mysql-8.0.23-linux-glibc2.12-x86_64 mysql
# chown -R mysql.dba mysql
# vi /etc/my.cnf
[client]
port = 3306
socket = /tmp/mysql.sock
[mysqld]
user = mysql
port = 3306
basedir = /usr/local/mysql
datadir = /mysql/data
log-error= /mysql/log/mysql_error.log
https://dev.mysql.com/doc/refman/8.0/en/server-system-variable-reference.html
# su - mysql
$ cd /usr/local/mysql/bin
$ ./mysqld --defaults-file=/etc/my.cnf --initialize-insecure
--initialize : 기본 데이터베이스 생성, 임의의 패스워드로 root 계정을 생성 (패스워드는 로그에서 확인)
--initialize-insecure : 기본 데이터베이스 생성, 빈 암호로 root 계정 생성
$ ./mysqld_safe --defaults-file=/etc/my.cnf &
$ ps -ef | grep mysqld
mysql 2840 2790 0 17:01 pts/0 00:00:00 /bin/sh ./mysqld_safe --defaults-file=/etc/my.cnf
mysql 3091 2840 9 17:01 pts/0 00:00:02 /usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql --datadir=/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --log-error=/mysql/log/mysql_error.log --pid-file=MySQL-S1.pid --socket=/tmp/mysql.sock --port=3306
./mysql -u root
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.23 MySQL Community Server - GPL
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
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> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.01 sec)
$ ./mysqladmin -u root -p shutdown
Enter password:
2021-05-31T08:04:30.631429Z mysqld_safe mysqld from pid file /mysql/data/MySQL-S1.pid ended
[1]+ Done ./mysqld_safe --defaults-file=/etc/my.cnf
# vi /usr/lib/systemd/system/mysqld.service
[Unit]
Description=MySQL Server
After=network.target
[Install]
WantedBy=multi-user.target
[Service]
Type=forking
User=mysql
Group=dba
ExecStart=/usr/local/mysql/support-files/mysql.server start
# systemctl daemon-reload
📌 systemctl 명령어를 실행하기 위해서는 일반 계정에 sudo 권한 필요
# visudo mysql ALL=NOPASSWD: /usr/bin/systemctl
🔧 systemctl 명령어로 MySQL 실행 / 중지
# su - mysql $ sudo systemctl start mysqld.service $ sudo systemctl stop mysqld.service
$ vi ~/.bash_profile
MySQL=/usr/local/mysql/bin
PATH=$PATH:$HOME/.local/bin:$HOME/bin:$MySQL
$ source ~/.bash_profile
$ echo $PATH
/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/mysql/.local/bin:/home/mysql/bin:/home/mysql/.local/bin:/home/mysql/bin:/usr/local/mysql/bin
$ mysql_secure_installation
Securing the MySQL server deployment.
Connecting to MySQL using a blank password.
VALIDATE PASSWORD COMPONENT can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD component?
Press y|Y for Yes, any other key for No: No
Please set the password for root here.
New password:
Re-enter new password:
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.
Remove anonymous users? (Press y|Y for Yes, any other key for No) : Y
Success.
Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : Y
Success.
By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : Y
- Dropping test database...
Success.
- Removing privileges on test database...
Success.
Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y
Success.
All done!
🔧 변경된 root 패스워드로 MySQL 접속
$ mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 13 Server version: 8.0.23 MySQL Community Server - GPL Copyright (c) 2000, 2021, Oracle and/or its affiliates. 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>