Mariadb (mysql)

安裝
yum list | grep mariadb
yum list | grep mariadb-servermysql

yum install mariadb
yum install mariadb-serversql

systemctl start mariadb
systemctl is-enabled mariadb
systemctl enable mariadb
systemctl disable mariadbvim

未正常關閉
rm -f /var/lib/mysql/mysql.sock
service mysqld startsocket

修改端口(添加)
vi /etc/my.cnf
[mysqld]
port=3306ide

指定主機登錄
mysql -u root -p [-h 192.168.5.116] ui

 

添加遠程登陸用戶
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";spa

FLUSH PRIVILEGES;.net

root@% 遠程用戶
root@:1 root@127.0.0.1 使用TCP/IP鏈接
root@localhost 使用Unix socket鏈接server

 

臨時密碼
vi /etc/my.cnf
skip-grant-tables=1
update mysql.user set authentication_string=password('123456') where user='root' and Host ='localhost';ip

經過# grep "password" /var/log/mysqld.log 命令獲取MySQL的臨時密碼
[Note] A temporary password is generated for root@localhost: 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源
http://dev.mysql.com/downloads/repo/yum/
http://repo.mysql.com/

wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm

sudo 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便可
 

相關文章
相關標籤/搜索