系统与软件信息
操作系统:CentOS Linux release 7.4.1708 (Core)
MySQL Version :5.7.37
添加mysql-5.7 yum源包
cd /etc/yum.repos.d/
mkdir bak
mv *.repo bak
cat mysql-community.repo
[mysql-5.7-community]
name=MySQL 5.7 Community Server
baseurl=https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql-5.7-community-el7-$basearch/
enabled=1
gpgcheck=1
gpgkey=https://repo.mysql.com/RPM-GPG-KEY-mysql
清理缓存yum源
yum clean all
yum makecache
安装MySQL数据库
[root@localhost ~]# yum install mysql mysql-community-server -y

开启MySQL服务
[root@localhost ~]# systemctl start mysqld
[root@localhost ~]# systemctl status mysqld.service
[root@localhost ~]# grep "password" /var/log/mysqld.log 日志文件中找出密码:
密码为:zY,GldJyq6Ia
修改MySQL密码
[root@localhost ~]# mysql -uroot -p
输入初始密码:zY,GldJyq6Ia
更改密码
set password for root@localhost = password('Admin@1234');
这样MySQL安装成功了
注:数据库命令
1. 创建数据库
create database 数据库名;
如:create database itsource;
2. 切换到指定数据库
use 数据库名;
如:use itsource;
3. 显示数据库列表
show databases;
4. 显示数据库建立语句
show create database 数据库名;
如:show create database itsource;
5. 修改数据库
alter database 数据库名 选项;
6. 删除数据库
drop database 数据库名;
修改数据表
alter table 数据表名 选项;
7. 新增字段
alter table 数据表名 add column 字段名 类型 修饰语句 位置
如:alter table news add column newstime timestamp default current_timestamp after content;
8. 修改字段定义
alter table 数据表名 modify column 字段名 新的定义
如:alter table news modify column content longtext;
9. 修改字段名及定义
alter table 数据表名 change column 旧字段名 新字段名 新的定义;
10. 删除字段
alter table 数据表名 drop column 字段名;
如:alter table news drop column title;