- 开启远程登录(或局域网访问)
use mysql;
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION;
flush privileges;
select host,user from user;
- Access denied for user ''@'localhost' to database 'mysql'
1. 关闭mysql
service mysqld stop
2. 屏蔽权限
mysqld_safe --skip-grant-table
屏幕出现: Starting demo from .....
3. 新开起一个终端输入
mysql -u root mysql
mysql> delete from user where USER='';
mysql> FLUSH PRIVILEGES;//记得要这句话,否则如果关闭先前的终端,又会出现原来的错误
mysql> \q
- centos7安装mysql
- 下载、安装仓库
在命令行中输入
wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
- 安装本地包
yum -y install mysql57-community-release-el7-10.noarch.rpm
- 安装mysql
yum -y install mysql-community-server
- 启动mysql,然后查看启动状态
systemctl start mysqld.service
systemctl status mysqld.service
- 查看root的随机密码
grep "password" /var/log/mysqld.log
- 使用随机密码登录mysql
mysql -uroot -p
# 输入上步找到的密码
- 修改默认密码
# 先修改密码规则,可以使用简单密码
mysql> set global validate_password_policy=0;
mysql> set global validate_password_length=1;
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'new password';
- 删除本地仓库,已免经常更新
yum -y remove mysql57-community-release-el7-10.noarch
- mysql编码utf8
- 查看当前编码
show variables like 'character%'
mysql> show variables like 'character%';
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | latin1 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | latin1 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)
- 修改配置中编码
# 退出mysql
exit
# 然后编辑配置文件
[root@VM_0_14_centos ~]# vim /etc/my.cnf
# 在[mysqld] 下面添加下行数据
character_set_server=utf8
# 保存退出
:wq
- 重启mysql
systemctl restart mysqld
- mysql导入导出
- mysql数据库导出
输入以下命令之后再输入密码即可导出到指定位置
[root@VM_0_14_centos ~]# mysqldump -uroot -p nhh_vendor_management_test > /root/vm.sql
- mysql数据库导入
登录数据并新建数据库
create datatable dbname;
导入数据库
[root@VM_0_14_centos ~]# mysql -uroot -p vm < /root/vm.sql