您好,登錄后才能下訂單哦!
[root@localhost ~]# cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)
#yum install mysql mysql-server mysql-devel
安裝mysql-server失敗,如下圖:
[root@localhost ~]# yum install mysql-server
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
這是因為CentOS 7用mariadb代替了MySQL數據庫軟件。
有兩種解決辦法:
1、方法一:安裝mariadb
MariaDB數據庫管理系統是MySQL的一個分支,主要由開源社區在維護,采用GPL授權許可。開發這個分支的原因之一是:甲骨文公司收購了MySQL后,有將MySQL閉源的潛在風險,因此社區采用分支的方式來避開這個風險。MariaDB的目的是完全兼容MySQL,包括API和命令行,使之能輕松成為MySQL的代替品。
安裝mariadb,大小59 M。
[root@localhost ~]# yum install mariadb-server mariadb
mariadb數據庫的相關命令是:
systemctl start mariadb #啟動MariaDB
systemctl stop mariadb #停止MariaDB
systemctl restart mariadb #重啟MariaDB
systemctl enable mariadb #設置開機啟動
所以先啟動數據庫
[root@localhost ~]# systemctl start mariadb
然后就可以正常使用mysql了
[root@localhost ~]# mysql -u root -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 5.5.41-MariaDB MariaDB Server
Copyright (c) 2000, 2014, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.00 sec)
MariaDB [(none)]>
安裝mariadb后顯示的也是 MariaDB [(none)]> ,可能看起來有點不習慣。下面是第二種方法。
2、方法二:官網下載安裝mysql-server
下載mysql:
wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
源碼安裝:
rpm -ivh mysql-community-release-el7-5.noarch.rpm
安裝服務:
yum install mysql-community-server
安裝成功后重啟mysql服務。
service mysqld restart
初次安裝mysql,root賬戶沒有密碼。
[root@localhost ~]# mysql -u root
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.6.26 MySQL Community Server (GPL)
Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.01 sec)
mysql>
設置mysql登錄密碼:
mysql> set password for 'root'@'localhost' =password('password');
Query OK, 0 rows affected (0.00 sec)
mysql>
不需要重啟數據庫即可生效。
在mysql安裝過程中如下內容:
Installed:
mysql-community-client.x86_64 0:5.6.26-2.el7 mysql-community-devel.x86_64 0:5.6.26-2.el7
mysql-community-libs.x86_64 0:5.6.26-2.el7 mysql-community-server.x86_64 0:5.6.26-2.el7
Dependency Installed:
mysql-community-common.x86_64 0:5.6.26-2.el7
Replaced:
mariadb.x86_64 1:5.5.41-2.el7_0 mariadb-devel.x86_64 1:5.5.41-2.el7_0 mariadb-libs.x86_64 1:5.5.41-2.el7_0
mariadb-server.x86_64 1:5.5.41-2.el7_0
所以安裝完以后mariadb自動就被替換了,將不再生效。
[root@localhost ~]# rpm -qa |grep mariadb
[root@localhost ~]#
1、編碼
mysql配置文件為/etc/my.cnf
最后加上編碼配置
[mysql]
default-character-set =utf8
這里的字符編碼必須和/usr/share/mysql/charsets/Index.xml中一致。
2、遠程連接設置
把在所有數據庫的所有表的所有權限賦值給位于所有IP地址的root用戶。
mysql> grant all privileges on . to root@'%'identified by 'password';
如果是新用戶而不是root,則要先新建用戶
mysql>create user 'username'@'%' identified by 'password';
此時就可以進行遠程連接了。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。