centos7上面没有mysql,它的数据库名字叫做mariadb
[root@localhost ~]#yum install mariadb-server -y
[root@localhost ~]#systemctl start mariadb.service
[root@localhost ~]#systemctl stop firewalld
[root@localhost ~]#setenforce 0
[root@localhost ~]#ss -natp |grep 3306 #数据库端口3306
LISTEN 0 50 *:3306 *:* users:(("mysqld",pid=2478,fd=14))
[root@localhost ~]#mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.68-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]>
[root@localhost ~]#mysql_secure_installation #初始化设置 先输入密码 一路回车
mariadb一般不使用
使用yum安装mysql
手写配置文件官方源,5.7.3版本,有初始的随机密码
[root@localhost ~]#cat >/etc/yum.repos.d/mysql.repo <<EOF
> [mysql57-community]
> name=MySQL 5.7 Community Server
> baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/x86_64/
> enabled=1
> gpgcheck=0
> EOF
#多行重定向写mysql.repo配置官网mysql的yum源
[root@localhost ~]#systemctl stop firewalld
[root@localhost ~]#setenforce 0
setenforce: SELinux is disabled
[root@localhost ~]#yum -y install mysql-community-server
#安装mysql数据库
[root@localhost ~]#systemctl start mysqld
[root@localhost ~]#ss -natp|grep 3306
LISTEN 0 80 :::3306 :::* users:(("mysqld",pid=40798,fd=21))
[root@localhost ~]#
[root@localhost ~]#grep password /var/log/mysqld.log
#在/var/log/mysqld.log日志文件中过滤password关键字查看初始的登录密码,注意无前面的空格
2024-03-13T07:56:54.672419Z 1 [Note] A temporary password is generated for root@localhost: yinYQQZV=9,l
[root@localhost ~]#mysql -uroot -p'yinYQQZV=9,l'
#mysql -uroot -p'查到的随机密码'
#登录数据库,注意密码有特殊符号是使用引号
#修改密码策略
set global validate_password_policy=0;
set global validate_password_length=1;
alter user root@'localhost' identified by 'abc123'; #修改数据库密码
第一步先关闭防火墙 核心防护
第二步下载yum源,然后安装mysql
下载完之后,开启mysql
mysql数据库修改密码
set global validate_password_policy=0;
set global validate_password_length=1; #修改密码策略
alter user root@localhost identified by 'abc123';
#修改用户root@localhost的密码为abc123
注意数据库的mysql语句需要以 ; 结尾才能执行成功
root@localhost和root@10.0.0.1是俩个用户。
quit; #退出数据库
mysql -uroot -p'abc123'
#使用新密码登录数据库成功,密码修改成功
数据库的创建与使用
登录数据库后输入 show databases; (注意分号结尾)表示查看所有数据库,如上是默认库截图
show create database +库名;查看某个库信息,如下查看默认库sys信息
create database +库名; 创建数据库XX,如下创建class库
use +库名;进入某个库,如下进入class库
我们看到使用数据库,不能显示当前位置,还没有补全,打错命令还需要重新打,接下来我们就来优化mysql数据库吧
安装mycli 插件 客户端工具
mycli 和 mysql 都是客户端工具
[root@localhost opt]#yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel libffi-devel
[root@localhost opt]#tar zxvf Python-3.7.7_.tgz
[root@localhost Python-3.7.7]#cd Python-3.7.7/
[root@localhost Python-3.7.7]#./configure --prefix=/usr/local/Python-3.7.7/
[root@localhost Python-3.7.7]#make
[root@localhost Python-3.7.7]#make install
[root@localhost Python-3.7.7]#ln -s /usr/local/Python-3.7.7/bin/python3.7 /usr/bin/python37
[root@localhost Python-3.7.7]#ln -s /usr/local/Python-3.7.7/bin/pip3.7 /usr/bin/pip37
[root@localhost Python-3.7.7]#pip37 install mycli -i http://mirrors.aliyun.com/pypi/simple --trusted-host mirrors.aliyun.com
[root@localhost Python-3.7.7]#ln -s /usr/local/Python-3.7.7/bin/mycli /usr/bin/mycli
[root@localhost Python-3.7.7]#mycli -u root -p 123123
[root@localhost ~]#vim /etc/my.cnf
[mysql]
prompt=(\\u@\\h) [\\d]>\\_
auto-rehash
随后再次安装路径
接下来见证奇迹,打命令就可以补全了
mycli 官网 点击就可进入
MyCLI is a command line interface for MySQL, MariaDB, and Percona with auto-completion and syntax highlighting.
进入配置文件 vim /etc/my.cnf 修改
[mysql]
prompt=(\\u@\\h) [\\d]>\\_
auto-rehash
但是,我们可以看到打命令的时候,有时候会补全,有时候并没有作用