- 下载mysql源安装包
wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
安装mysql源
yum localinstall mysql57-community-release-el7-8.noarch.rpm检查mysql源是否安装成功
yum repolist enabled | grep "mysql.*-community.*"安装MySQL
yum install mysql-community-server启动MySQL服务
systemctl start mysqld查看MySQL的启动状态
systemctl status mysqld查看root用户的密码,(冒号后面得就是密码)
grep 'temporary password' /var/log/mysqld.log登录root
mysql -uroot -p修改密码
ALTER USER 'root'@'localhost' IDENTIFIED BY 'newPassword';添加远程用户
GRANT ALL PRIVILEGES ON *.* TO 'xkj'@'%' IDENTIFIED BY 'a' WITH GRANT OPTION;修改编码集
vim /etc/my.cnf
(在 [mysqld] 下加)
character_set_server=utf8
init_connect='SET NAMES utf8'
- 查看编码集
show variables like '%character%' - 给用户添加某个database权限
grant all on dbName.* to 'xkj'@'localhost'; - 查看所有用户及权限
SELECT DISTINCT CONCAT('User: ''',user,'''@''',host,''';') AS query FROMmysql.user; - 修改字段类型:
alter table address modify column city varchar(50) - 修改表编码集:
ALTER TABLE tableName DEFAULT CHARACTER SET utf8; - 设置编码集:
set character_set_database=utf8; - 查看表的编码集:
show create table tableName