安装
yum list | grep mariadb yum list | grep mariadb-serveryum install mariadb
yum install mariadb-serversystemctl start mariadb
systemctl is-enabled mariadb systemctl enable mariadb systemctl disable mariadb未正常关闭
rm -f /var/lib/mysql/mysql.sock service mysqld start修改端口(添加)
vi /etc/my.cnf [mysqld] port=3306指定主机登陆
mysql -u root -p [-h 192.168.5.116]
添加远程登录用户
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'IDENTIFIED BY '123456' WITH GRANT OPTION; GRANT ALL PRIVILEGES ON *.* TO 'user'@'localhost' IDENTIFIED BY 'password'; grant all on *.* to "root"@"%" identified by "123456";FLUSH PRIVILEGES;
root@% 远程用户
root@:1 root 使用TCP/IP连接 root 使用Unix socket连接
临时密码
vi /etc/my.cnf skip-grant-tables=1 update mysql.user set authentication_string=password('123456') where user='root' and Host ='localhost';通过# grep "password" /var/log/mysqld.log 命令获取MySQL的临时密码
[Note] A temporary password is generated for root: waQ,qR%be2(5 用该密码登录到服务端后,必须马上修改密码, 且密码包含数字,小写,大写字母,特殊字符 ALTER USER USER() IDENTIFIED BY 'XXXX'
修改密码, 如有需要, 需在GRANT之后运行, 否则无法登陆
mysqladmin -u root password 'newpassword'修复
# systemctl stop mariadb # mysqld_safe --user=mysql --skip-grant-tables --skip-networking & # mysql -u root mysql mysql> UPDATE user SET Password=PASSWORD('newpassword') where USER='root'; mysql> FLUSH PRIVILEGES; mysql> quit # systemctl start mariadb # mysql -uroot -p Enter password: <输入新设的密码newpassword>CentOS7下载mysql的repo源
wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpmsudo rpm -ivh mysql-community-release-el7-5.noarch.rpm
yum localinstall mysql57-community-release-el7-8.noarch.rpm安装这个包后,会获得两个mysql的yum repo源:
/etc/yum.repos.d/mysql-community.repo, /etc/yum.repos.d/mysql-community-source.repo选择mysql安装版本
修改vim /etc/yum.repos.d/mysql-community.repo源,改变默认安装的mysql版本 比如要安装5.6版本,将5.7源的enabled=1改成enabled=0 然后再将5.6源的enabled=0改成enabled=1即可