Centos 7安裝MySql(5.7.26解壓版)

Centos 7安裝MySql(5.7.26解壓版)


1、卸載centos7自帶的 MariaDB
[root@VM_0_14_centos ~]# rpm -qa|grep mariadb
mariadb-libs-5.5.56-2.el7.x86_64
[root@VM_0_14_centos ~]# rpm -e --nodeps mariadb-libs-5.5.56-2.el7.x86_64
error: package mariadb-libs-55.56mariadb-libs-5.5.56-2.el7.x86_64 is not installed
[root@VM_0_14_centos ~]#
2、刪除/etcmy.cnf配置文件(如果存在的話)、檢查mysql是否存在
[root@VM_0_14_centos ~]# rm -rf /etc/my.cnf
[root@VM_0_14_centos ~]# rpm -qa | grep mysql
3、官網(wǎng)下載源碼包
下載地址
4仁期、解壓安裝包
tar -xvf mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz
5、修改解壓出來(lái)的文件夾移動(dòng)到 /usr/local/mysql
[root@VM_0_14_centos download]# mv /usr/local/download/mysql-5.7.26-linux-glibc2.12-x86_64 /usr/local/mysql
6、進(jìn)入mysql目錄跛蛋,新建data目錄
[root@VM_0_14_centos download]# cd /usr/local/mysql/
[root@VM_0_14_centos mysql]# mkdir data 
7熬的、創(chuàng)建系統(tǒng)用戶(hù)組和用戶(hù)
[root@VM_0_14_centos mysql]# cat /etc/group   --查看所有用戶(hù)組信息是否存在mysql組,不存在則創(chuàng)建赊级,存在則直接新建用戶(hù)
[root@VM_0_14_centos mysql]# groupadd mysql   ---新建一個(gè)msyql組
[root@VM_0_14_centos mysql]# cat /etc/passwd|grep mysql  ---查看是否存在mysql用戶(hù)
[root@VM_0_14_centos mysql]# useradd -g mysql mysql   ---新建msyql用戶(hù)
8押框、修改當(dāng)前目錄權(quán)限
[root@VM_0_14_centos mysql]# chown -R mysql:mysql /usr/local/mysql/
9理逊、初始化數(shù)據(jù)庫(kù)
[root@VM_0_14_centos bin]# ./mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
./mysqld: error while loading shared libraries: libnuma.so.1: cannot open shared object file: No such file or directory

若報(bào)如下錯(cuò)

./mysqld: error while loading shared libraries: libnuma.so.1: cannot open shared object file: No such file or directory

yun安裝numactl

[root@VM_0_14_centos bin]# yum remove libnuma.so.1;
[root@VM_0_14_centos bin]# yum -y install numactl.x86_64

若報(bào)如下錯(cuò)

libaio.so.1: cannot open shared object file: No such file or directory

yun安裝libaio

yum install libaio*
10、重新初始化成功骑歹,最后是初始化 root 登錄密碼
[root@VM_0_14_centos bin]# ./mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
2019-06-29T05:24:18.538969Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-06-29T05:24:19.722625Z 0 [Warning] InnoDB: New log files created, LSN=45790
2019-06-29T05:24:19.876417Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2019-06-29T05:24:19.979084Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 257f6850-9a2e-11e9-9c9e-525400dc2e19.
2019-06-29T05:24:19.988044Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2019-06-29T05:24:19.988863Z 1 [Note] A temporary password is generated for root@localhost: 8w.9!6U4%m3
11、將 mysql加入服務(wù)
[root@VM_0_14_centos bin]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
12墨微、配置my.cnf

搜索my.cnf

[root@VM_0_14_centos bin]# find / -name my.cnf

找到后復(fù)制到 /etc/my.cnf并進(jìn)行如下編輯,若找不到則在/etc下手動(dòng)編輯一個(gè)

[root@VM_0_14_centos bin]# vim /etc/my.cnf
[mysqld]
character_set_server=utf8
init_connect='SET NAMES utf8'
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
socket=/tmp/mysql.sock
#不區(qū)分大小寫(xiě)
lower_case_table_names = 1
#不開(kāi)啟sql嚴(yán)格模式
sql_mode = "STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
log-error=/var/log/mysqld.log
pid-file=/usr/local/mysql/data/mysqld.pid
13翘县、添加開(kāi)機(jī)啟動(dòng)修改basedirdatadir
[root@VM_0_14_centos bin]# vi /etc/init.d/mysql
14谴分、開(kāi)機(jī)自啟
這里需要修改锈麸,Centos7變了
[root@VM_0_14_centos bin]# chkconfig --add mysql
[root@VM_0_14_centos bin]# chkconfig mysql on
15、啟動(dòng)mysql服務(wù)
[root@VM_0_14_centos bin]# service mysql stop
 ERROR! MySQL server PID file could not be found!
[root@VM_0_14_centos bin]# service mysql start
Starting MySQL. SUCCESS!
16牺蹄、查詢(xún)列表
[root@VM_0_14_centos bin]# chkconfig | grep -i mysql

Note: This output shows SysV services only and does not include native
      systemd services. SysV configuration data might be overridden by native
      systemd configuration.

      If you want to list systemd services use 'systemctl list-unit-files'.
      To see services enabled on particular target use
      'systemctl list-dependencies [target]'.

mysql           0:off   1:off   2:on    3:on    4:on    5:on    6:off
如果看到mysql的服務(wù)忘伞,并且3,4,5都是on的話則成功沙兰,如果是off,則執(zhí)行
[root@VM_0_14_centos bin]# chkconfig --level 345 mysql on
17鼎天、重啟電腦 reboot,驗(yàn)證是否開(kāi)機(jī)自啟mysql服務(wù)
[root@VM_0_14_centos ~]# netstat -na | grep 3306
tcp6       0      0 :::3306                 :::*                    LISTEN  
18斋射、Mysq連接配置

連接Mysql,使用root賬號(hào)登錄【使用初始化時(shí)默認(rèn)密碼】

[root@VM_0_14_centos ~]# cd /usr/local/mysql/bin/
[root@VM_0_14_centos bin]# ./mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.26

Copyright (c) 2000, 2019, 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> 
19涧至、修改root密碼
Server version: 5.7.26

Copyright (c) 2000, 2019, 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> set PASSWORD = PASSWORD('1234567');    
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> 
20桑包、允許遠(yuǎn)程訪問(wèn)
mysql> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> select host,user from user;
+-----------+---------------+
| host      | user          |
+-----------+---------------+
| localhost | mysql.session |
| localhost | mysql.sys     |
| localhost | root          |
+-----------+---------------+
3 rows in set (0.00 sec)

mysql> create user 'root'@'%' identified by '1234567';
Query OK, 0 rows affected (0.01 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)

mysql> 
21、授權(quán)數(shù)據(jù)庫(kù)操作
mysql> grant all on finance.* to 'root'@'%' identified by '1234567' with grant option;
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'; 
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
22蓖康、使用連接程序進(jìn)行連接,如果連接不上蒜焊,那么需要防火墻開(kāi)放指定端口
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市鳖悠,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌乘综,老刑警劉巖套硼,帶你破解...
    沈念sama閱讀 212,542評(píng)論 6 493
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場(chǎng)離奇詭異九妈,居然都是意外死亡,警方通過(guò)查閱死者的電腦和手機(jī)萌朱,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 90,596評(píng)論 3 385
  • 文/潘曉璐 我一進(jìn)店門(mén)策菜,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái),“玉大人又憨,你說(shuō)我怎么就攤上這事〈垒海” “怎么了?”我有些...
    開(kāi)封第一講書(shū)人閱讀 158,021評(píng)論 0 348
  • 文/不壞的土叔 我叫張陵蒋情,是天一觀的道長(zhǎng)耸携。 經(jīng)常有香客問(wèn)我棵癣,道長(zhǎng)夺衍,這世上最難降的妖魔是什么? 我笑而不...
    開(kāi)封第一講書(shū)人閱讀 56,682評(píng)論 1 284
  • 正文 為了忘掉前任河劝,我火速辦了婚禮壁榕,結(jié)果婚禮上赎瞎,老公的妹妹穿的比我還像新娘。我一直安慰自己牡辽,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 65,792評(píng)論 6 386
  • 文/花漫 我一把揭開(kāi)白布态辛。 她就那樣靜靜地躺著挺尿,像睡著了一般。 火紅的嫁衣襯著肌膚如雪编矾。 梳的紋絲不亂的頭發(fā)上,一...
    開(kāi)封第一講書(shū)人閱讀 49,985評(píng)論 1 291
  • 那天,我揣著相機(jī)與錄音蜗细,去河邊找鬼。 笑死炉媒,一個(gè)胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的缎岗。 我是一名探鬼主播,決...
    沈念sama閱讀 39,107評(píng)論 3 410
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼传泊,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼鸭巴!你這毒婦竟也來(lái)了?” 一聲冷哼從身側(cè)響起鹃祖,我...
    開(kāi)封第一講書(shū)人閱讀 37,845評(píng)論 0 268
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤,失蹤者是張志新(化名)和其女友劉穎校读,沒(méi)想到半個(gè)月后,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體歉秫,經(jīng)...
    沈念sama閱讀 44,299評(píng)論 1 303
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 36,612評(píng)論 2 327
  • 正文 我和宋清朗相戀三年雅潭,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了却特。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 38,747評(píng)論 1 341
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡裂明,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出扳碍,到底是詐尸還是另有隱情仙蛉,我是刑警寧澤笋敞,帶...
    沈念sama閱讀 34,441評(píng)論 4 333
  • 正文 年R本政府宣布夯巷,位于F島的核電站,受9級(jí)特大地震影響趁餐,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜后雷,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 40,072評(píng)論 3 317
  • 文/蒙蒙 一吠各、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧贾漏,春花似錦、人聲如沸盒齿。這莊子的主人今日做“春日...
    開(kāi)封第一講書(shū)人閱讀 30,828評(píng)論 0 21
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)。三九已至符匾,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間甸各,已是汗流浹背。 一陣腳步聲響...
    開(kāi)封第一講書(shū)人閱讀 32,069評(píng)論 1 267
  • 我被黑心中介騙來(lái)泰國(guó)打工趣倾, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留某饰,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 46,545評(píng)論 2 362
  • 正文 我出身青樓诫尽,卻偏偏與公主長(zhǎng)得像,于是被迫代替她去往敵國(guó)和親牧嫉。 傳聞我的和親對(duì)象是個(gè)殘疾皇子减途,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 43,658評(píng)論 2 350

推薦閱讀更多精彩內(nèi)容