1,安装虚拟机桥接,和当前主机在同一个网络下,
2安装系统centos7,X86-64
3,关闭防火墙:systemctl stopfirewalld.service
用ftp连接上系统
卸载mysql yum remove mysql mysql-server mysql-libscompat-mysql51
检查是否有mysql文件:find / -name
mysql
rm -rf/usr/lib/mysql
mysql更改端口
修改/etc/my.cnf
添加port=3308
修改后如下
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
port=3308
user=mysql
#Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
default-character-set=utf8
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
用yum命令安装mariaDB:yuminstallmariadb-server (默认安装,yes)
MariaDB服务开启:systemctl start mariadb #开启服务
设置为开机启动: systemctl enable mariadb #设置为开机自启动服务
首次安装进行数据库的配置:mysql_secure_installation
Enter current password for root (enter fornone): #输入数据库超级管理员root的密码(注意不是系统root的密码),第一次进入还没有设置密码则直接回车
Set root password? [Y/n] #设置密码,y
New password: #新密码
Re-enter new password: #再次输入密码
Remove anonymous users? [Y/n] #移除匿名用户,y
Disallow root login remotely? [Y/n] #拒绝root远程登录,n,不管y/n,都会拒绝root远程登录
Remove test database and access to it?[Y/n] #删除test数据库,y:删除。n:不删除,数据库中会有一个test数据库,一般不需要
Reload privilege tables now? [Y/n] #重新加载权限表,y。或者重启服务也许
查看用户状态selecthost,userfrommysql.user;
创建用户 createuser'whyzt'@'%'identifiedby'whyztld@2020';
grant all privileges on *.* to whyzt@”%”;
授权GRANT ALL PRIVILEGES ON *.* TO whyzt @"%" IDENTIFIED BY " whyztld@2020";
FLUSH PRIVILEGES;
修改密码set password for ' whyzt '@'%'=password(‘whyztld@2020’)
· MariaDB[(none)]>show global variables like 'port'; #查看端口号
· MariaDB [(none)]>status; #查看mariadb的基本信息
修改端口不区分大小写 /etc/my.cnf中mysqld 下面加入以下内容
port=47280
lower_case_table_names=1
然后重启
设置MariaDB字符集为utf-8
1)/etc/my.cnf文件
在 [mysqld] 标签下添加
init_connect='SET collation_connection = utf8_unicode_ci'
init_connect='SET NAMES utf8'
character-set-server=utf8
collation-server=utf8_unicode_ci
skip-character-set-client-handshake
2)/etc/my.cnf.d/client.cnf文件
在 [client] 标签下添加
default-character-set=utf8
3)/etc/my.cnf.d/mysql-clients.cnf 文件
在 [mysql] 标签下添加
default-character-set=utf8
4)重启服务
[root@mini ~]#systemctl restart mariadb
先查看mysql数据库中的user表
[root@mini ~]# mysql -u root -p #先通过本地链接进入数据库
MariaDB [(none)]>use mysql;
MariaDB [mysql]>select host, user from user;
+-----------+------+
| host | user |
+-----------+------+
|127.0.0.1| root |
| ::1 | root |
| mini | root|
+-----------+------+
3rowsinset (0.00sec)
3)将与主机名相等的字段改为"%" ,我的主机名为mini,
MariaDB [mysql]> update user set host='%'where host='mini';
Query OK, 1row affected (0.00sec)
Rows matched: 1 Changed:1 Warnings:0
MariaDB [mysql]>selecthost, user from user;
+-----------+------+
| host | user|
+-----------+------+
| % | root|
|127.0.0.1| root |
| localhost | root |
+-----------+------+
3rowsinset (0.00sec)
S
刷新权限表,或重启mariadb服务,一下二选一即可
MariaDB [mysql]>flush privileges;
Query OK, 0rows affected (0.00sec)
[root@mini ~]# systemctl restart mariadb