Skip to content

MySQL

Centos7安装MySQL

如果使用默认的yum源安装的是mariadb,版本比较低。

# MySQL yum源官网地址
# https://dev.mysql.com/downloads/repo/yum/

# 下载yum源
wget https://repo.mysql.com//mysql80-community-release-el7-1.noarch.rpm

# 安装yum源
rpm -ivh mysql80-community-release-el7-1.noarch.rpm

# 安装MySQL
yum install mysql-community-server.x86_64 mysql-community-client.x86_64 -y

# 启动服务
systemctl start mysqld.service

# 查看初始密码
cat /var/log/mysqld.log | grep pass

# 修改密码
alter user 'root'@'localhost' identified by 'your password';

MySQL语句

CREATE DATABASE db_name CHARACTER SET utf8 COLLATE utf8_general_ci; # 创建数据库

select FROM_UNIXTIME(1551422203); # 将时间戳转换为日期

select UNIX_TIMESTAMP('2019-03-01 13:44:00'); # 将日期转换为时间戳

update table_name set column_name is null;
update table_name set column_name=NULL;  # 设置字段为空

alter table table_name add column_name type; # 添加字段