一、Mysql介绍
MySQL是一个开放源码的小型关联式数据库管理系统,开发者为瑞典MySQL AB公司。目前MySQL被广泛地应用在Internet上的中小型网站中。由于其体积小、速度快、总体拥有成本低,尤其是开放源码这一特点,许多中小型网站为了降低网站总体拥有成本而选择了MySQL作为网站数据库。
二、Mysql启动
1.检查mysql是否启动
[root@control data]# ps -ef | grep mysqld
root 7856 2569 0 22:28 pts/0 00:00:00 grep --color=auto mysqld
2.查看mysql状态并启动
[root@control data]# systemctl enable --now mysqld
Created symlink /etc/systemd/system/multi-user.target.wants/mysqld.service → /usr/lib/systemd/system/mysqld.service.
[root@control data]# systemctl status mysqld.service
● mysqld.service - MySQL 8.0 database server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since Mon 2021-04-26 22:30:14 CST; 7s ago
Process: 8039 ExecStartPost=/usr/libexec/mysql-check-upgrade (code=exited, status=0/SUCCESS)
Process: 7960 ExecStartPre=/usr/libexec/mysql-prepare-db-dir mysqld.service (code=exited, status>
Process: 7936 ExecStartPre=/usr/libexec/mysql-check-socket (code=exited, status=0/SUCCESS)
Main PID: 7997 (mysqld)
Status: "SERVER_OPERATING"
Tasks: 38 (limit: 24900)
Memory: 418.5M
CGroup: /system.slice/mysqld.service
└─7997 /usr/libexec/mysqld --basedir=/usr
mysql进程查看
[root@control data]# ps -ef | grep mysqld
mysql 7997 1 2 22:30 ? 00:00:01 /usr/libexec/mysqld --basedir=/usr
root 8085 2569 0 22:31 pts/0 00:00:00 grep --color=auto mysqld
三、Mysql用户管理
1.验证登录mysql
①查看mysql版本
[root@control bin]# mysqladmin --version
mysqladmin Ver 8.0.13 for Linux on x86_64 (Source distribution)
②跳过mysql登录密码
[root@control ~]# vim /etc/my.cnf
[root@control ~]# cat /etc/my.cnf
#
# This group is read both both by the client and the server
# use it for options that affect everything
#
[client-server]
[mysqld]
explicit_defaults_for_timestamp=true
skip-grant-tables
#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
③修改密码
[root@control ~]# systemctl restart mysqld.service
[root@control ~]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 8.0.13 Source distribution
Copyright (c) 2000, 2018, 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>
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
Query OK, 0 rows affected (0.08 sec)
mysql> exit
Bye
去掉/etc/my.cnf添加内容,重启服务
[root@control ~]# vim /etc/my.cnf
[root@control ~]# systemctl restart mysqld.service
④登录mysql进行测试
[root@control ~]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.13 Source distribution
Copyright (c) 2000, 2018, 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>