安装mysql数据库时的一顿操作

记录最近按照mysql的一顿操作。

安装包:mysql-8.0.18-linux-x86_64-minimal.tar
下载地址:
https://dev.mysql.com/downloads/mysql/
https://dev.mysql.com/downloads/file/?id=490304

详细步骤:
解压:
tar -xvf mysql-8.0.18-linux-x86_64-minimal.tar
解压出三个文件:
mysql-8.0.18-linux-x86_64-minimal.tar.xz
mysql-router-8.0.18-linux-x86_64-minimal.tar.xz
mysql-test-8.0.18-linux-x86_64-minimal.tar.xz
只使用:mysql-8.0.18-linux-x86_64-minimal.tar.xz
再解压:
xz -d mysql-8.0.18-linux-x86_64-minimal.tar.xz
tar -xvf mysql-8.0.18-linux-x86_64-minimal.tar
得到目录:mysql-8.0.18-linux-x86_64-minimal

移动目录:
mv mysql-8.0.18-linux-x86_64-minimal /usr/local/mysql

groupadd mysql 创建mysql组
useradd -r -g mysql mysql 在mysql组中创建mysql用户
touch /etc/my.cnf

vi /etc/my.cnf

[mysqld]
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd

[mysqld_safe]
log-error=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid

[client]
default-character-set=utf8
socket=/tmp/mysql/mysql.sock

[mysql]
default-character-set=utf8
socket=/tmp/mysql/mysql.sock

#
# include all files from the config directory
#
!includedir /etc/my.cnf.d

cd /usr/local/
chown -R mysql:mysql mysql //指定目录的拥有者

cd mysql
./bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data //指定数据目录,注意root@localhost后的密码
192.168.91.171 root@localhost: +cwceuxtg@5YG

./bin/mysql_ssl_rsa_setup --datadir=/usr/local/mysql/data

cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql

vi /etc/init.d/mysql
basedir=/usr/local/mysql/
datadir=/usr/local/mysql/data

mkdir /tmp/mysql
mkdir /var/log/mariadb
touch /var/log/mariadb/mariadb.log
chown -R mysql:mysql /var/log/mariadb //授予mysql用户组访问权限
chown -R mysql:mysql /tmp/mysql

service mysql start
mysql -uroot -p
输入密码

mysql> use mysql;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
需要修改密码:
alter user ‘root’@‘localhost’ identified by ‘+cwceuxtg@5YO’;

mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> show tables;
OK!!!

你可能感兴趣的:(数据库)