MySQL57安装与设置

安装MySQL
添加mysql源

[root@localhost ~]# rpm -ivh http://repo.mysql.com//mysql57-community-release-el7-7.noarch.rpm

安装mysql
[root@localhost ~]# yum -y install mysql-community-server

启动mysql、检查状态、设置为开机自启
[root@localhost ~]# systemctl start mysqld
[root@localhost ~]# systemctl status mysqld
[root@localhost ~]# systemctl enable mysqld

第一次启动mysql,会在日志文件中生成root用户的一个随机密码,使用下面命令查看该密码
[root@localhost ~]# grep 'temporary password' /var/log/mysqld.log

修改root用户密码
[root@localhost ~]# mysql -u root -p
Enter password:

mysql> alter user 'root'@'localhost' identified by 'p@$$w0rd';

创建数据库(数据库名为:test)
mysql> create database test;

使用test数据库
mysql> use crashcourse;

执行sql脚本(使用source命令)
mysql> source /root/MySQLCrashCourse/create.sql;
mysql> source /root/MySQLCrashCourse/populate.sql;

查看可用数据库的列表
mysql> show databases;

查看当前数据库内可用表的列表
mysql> show tables;

显示表列(表名:customers)
mysql> show columns from customers;

显示服务器错误或警告消息
mysql> show errors;
mysql> show warnings;

安全管理
不应该在日常的MySQL操作中使用root

获得所有账号列表
mysql> use mysql;
mysql> select user from user;

创建用户账号
mysql> create user test1 identified by 'p@$$w0rd';

重命名用户账号
mysql> rename user test1 to test2;

删除用户账号
mysql> drop user test;

查看用户账号权限
mysql> show grants for test;

给用户账号授予权限
mysql> grant select on crashcourse.* to test;

撤销用户权限
mysql> revoke select on crashcourse.* from test;

更改用户口令
set password for test = password('n3w p@$$w0rd');

设置自己的口令
set password = password('n3w p@$$w0rd');

汉语支持:

vi /etc/my.cnf
···
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
symbolic-links=0
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
character-set-server = utf8
collation-server = utf8_general_ci

[client]
default-character-set = utf8
```

转载于:https://www.cnblogs.com/colman/p/11045699.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值