linux安装Mariadb10.5并修改端口
首先配置yum源
进入下方的文件进行配置
vim /etc/yum.repos.d/MariaDB.repo
填写下方内容
[mariadb]
name = MariaDB
baseurl = https:///mirrors.aliyun.com/mariadb/yum/10.5/centos8-amd64/
gpgkey=https:///mirrors.aliyun.com/mariadb/yum/RPM-GPG-KEY-MariaDB
module_hotfixes=1
gpgkey=https:///yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
安装Mariadb
清楚缓存
yum clean all && yum update #清除yum缓存并更新
安装mariadb服务端
yum install -y mariadb-server
开启自启并启动服务
systemctl enable mariadb && systemctl start mariadb
首次运行输入下方指令
mysql_secure_installation
没有错误的情况下出现如下提示
Enter current password for root (enter for none):–>初次运行直接回车
Switch to unix_socket authentication [Y/n] n –>是否unix_socket身份验证,建议不要使用
Set root password? [Y/n] Y –>是否设置root用户密码,输入y并回车或直接回车
New password: –>设置root用户的密码
Re-enter new password: –>再输入一次你设置的密码
Remove anonymous users? [Y/n]Y –>是否删除匿名用户,回车
Disallow root login remotely? [Y/n] –>是否禁止root远程登录(看情况使用默认Y),回车,
Remove test database and access to it? [Y/n] Y –>是否删除test数据库,回车
Reload privilege tables now? [Y/n] Y –>是否重新加载权限表,回车
出现成功表示安装完成
Thanks for using Mariadb!
遇到的奇怪问题:
想更改mysql里的user表数据将root
用户的host
从localhost更改为%
但是用普通的update
sql语句没有权限更改
报错如下
> UPDATE mysql.user SET Host='%' WHERE User='root' AND Host='localhost';
> View 'mysql.user' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them,
上方错误意思是无权进行更改
最终我的解决办法
执行下方命令创建一个新的用户
> CREATE USER 'root'@'%' IDENTIFIED BY '你的密码';
> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;
> FLUSH PRIVILEGES;
你的密码
设置密码
FLUSH PRIVILEGES;
刷新权限
如果想更改mysql的默认端口如下操作
编辑my.cnf.d
里面的server.cnf文件
# this is only for the mysqld standalone daemon
# 这里修改端口
[mysqld]
# 默认时没有这个的↓
port=3333
另外如果需要暴露到外部解开一段注释
# Allow server to accept connections on all interfaces.
# 将这段注释解开↓
bind-address=0.0.0.0
重启
systemctl restart mysqld