最新文章專題視頻專題問(wèn)答1問(wèn)答10問(wèn)答100問(wèn)答1000問(wèn)答2000關(guān)鍵字專題1關(guān)鍵字專題50關(guān)鍵字專題500關(guān)鍵字專題1500TAG最新視頻文章推薦1 推薦3 推薦5 推薦7 推薦9 推薦11 推薦13 推薦15 推薦17 推薦19 推薦21 推薦23 推薦25 推薦27 推薦29 推薦31 推薦33 推薦35 推薦37視頻文章20視頻文章30視頻文章40視頻文章50視頻文章60 視頻文章70視頻文章80視頻文章90視頻文章100視頻文章120視頻文章140 視頻2關(guān)鍵字專題關(guān)鍵字專題tag2tag3文章專題文章專題2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章專題3
問(wèn)答文章1 問(wèn)答文章501 問(wèn)答文章1001 問(wèn)答文章1501 問(wèn)答文章2001 問(wèn)答文章2501 問(wèn)答文章3001 問(wèn)答文章3501 問(wèn)答文章4001 問(wèn)答文章4501 問(wèn)答文章5001 問(wèn)答文章5501 問(wèn)答文章6001 問(wèn)答文章6501 問(wèn)答文章7001 問(wèn)答文章7501 問(wèn)答文章8001 問(wèn)答文章8501 問(wèn)答文章9001 問(wèn)答文章9501
當(dāng)前位置: 首頁(yè) - 科技 - 知識(shí)百科 - 正文

Linux下安裝配置MySQL

來(lái)源:懂視網(wǎng) 責(zé)編:小采 時(shí)間:2020-11-09 20:33:57
文檔

Linux下安裝配置MySQL

Linux下安裝配置MySQL:系統(tǒng):Ubuntu 16.04LTS 1\官網(wǎng)下載mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz 2\建立工作組: $su #groupadd mysql #useradd -r -g mysql mysql 3\創(chuàng)建目錄 #mkdir /usr/local/mysql #mkdir /usr/
推薦度:
導(dǎo)讀Linux下安裝配置MySQL:系統(tǒng):Ubuntu 16.04LTS 1\官網(wǎng)下載mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz 2\建立工作組: $su #groupadd mysql #useradd -r -g mysql mysql 3\創(chuàng)建目錄 #mkdir /usr/local/mysql #mkdir /usr/

系統(tǒng):Ubuntu 16.04LTS

1\官網(wǎng)下載mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz

2\建立工作組:

$su
#groupadd mysql
#useradd -r -g mysql mysql

3\創(chuàng)建目錄

#mkdir /usr/local/mysql
#mkdir /usr/local/mysql/data

4\解壓mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz,并拷貝至/usr/local/mysql

#tar -zxvf mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz
#cp -r /home/jieyamulu/mysql-5.7.18-linux-glibc2.5-x86_64/* /usr/local/mysql

5\修改mysql用戶對(duì)mysql以下及其子文件夾以下文件的權(quán)限,修改后可使用ll查看權(quán)限

root@Ice-***:/usr/local# chown -R mysql:mysql mysql
root@Ice-***:/usr/local# ll
總用量 44
drwxr-xr-x 11 root root 4096 5月 19 07:39 ./
drwxr-xr-x 11 root root 4096 2月 16 04:30 ../
drwxr-xr-x 2 root root 4096 2月 16 04:19 bin/
drwxr-xr-x 2 root root 4096 2月 16 04:19 etc/
drwxr-xr-x 2 root root 4096 2月 16 04:19 games/
drwxr-xr-x 2 root root 4096 2月 16 04:19 include/
drwxr-xr-x 4 root root 4096 2月 16 04:23 lib/
lrwxrwxrwx 1 root root 9 3月 29 14:11 man -> share/man/
drwxr-xr-x 10 mysql mysql 4096 5月 19 07:48 mysql/
drwxr-xr-x 2 root root 4096 2月 16 04:19 sbin/
drwxr-xr-x 8 root root 4096 2月 16 04:34 share/
drwxr-xr-x 2 root root 4096 2月 16 04:19 src/
root@Ice-***:/usr/local# cd mysql/
root@Ice-***:/usr/local/mysql# ll
總用量 64
drwxr-xr-x 10 mysql mysql 4096 5月 19 07:48 ./
drwxr-xr-x 11 root root 4096 5月 19 07:39 ../
drwxr-xr-x 2 mysql mysql 4096 5月 19 07:48 bin/
-rw-r--r-- 1 mysql mysql 17987 5月 19 07:48 COPYING
drwxr-xr-x 2 mysql mysql 4096 5月 19 07:41 data/
drwxr-xr-x 2 mysql mysql 4096 5月 19 07:48 docs/
drwxr-xr-x 3 mysql mysql 4096 5月 19 07:48 include/
drwxr-xr-x 5 mysql mysql 4096 5月 19 07:48 lib/
drwxr-xr-x 4 mysql mysql 4096 5月 19 07:48 man/
-rw-r--r-- 1 mysql mysql 2478 5月 19 07:48 README
drwxr-xr-x 28 mysql mysql 4096 5月 19 07:48 share/
drwxr-xr-x 2 mysql mysql 4096 5月 19 07:48 support-files/

6\修改(或新建)/etc/my.cnf 配置文件

root@Ice-***:/usr/local/mysql# vim /etc/my.cnf 
[mysqld] basedir=/usr/local/mysql/
datadir=/usr/local/mysql/data
:wq

7\最關(guān)鍵的初始化

# cd /usr/local/mysql/
root@Ice-***:/usr/local/mysql# ./bin/mysqld --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --initialize

2017-05-19T00:15:46.529420Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2017-05-19T00:15:47.066125Z 0 [Warning] InnoDB: New log files created, LSN=45790
2017-05-19T00:15:47.213711Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2017-05-19T00:15:47.286951Z 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: 4e958344-3c28-11e7-8334-c8d3ffd2db82.
2017-05-19T00:15:47.292857Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2017-05-19T00:15:47.294758Z 1 [Note] A temporary password is generated for root@localhost: YjaotQk*2ew4

初始密碼要記住
這里可能會(huì)出現(xiàn)很多問(wèn)題,比如:

Installing MySQL system tables..../bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory

缺少依賴關(guān)系包

解決方法:sudo apt-get install libaio-dev

還有可能是之前步驟不對(duì)導(dǎo)致了操作data文件的權(quán)限不夠等等.按照步驟來(lái),缺少什么裝什么(有提示),到了這里應(yīng)該就初始化成功了,那幾個(gè)Warning,值得注意的是Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.有時(shí)間可以查下是怎么回事,這條忽略也沒(méi)影響.

8\不要著急啟動(dòng),現(xiàn)在還啟動(dòng)不了.執(zhí)行代碼,將mysql下除了data文件夾外的文件變?yōu)閞oot權(quán)限

root@Ice-***:/usr/local/mysql# chown -R root .
root@Ice-***:/usr/local/mysql# chown -R mysql data

9\啟動(dòng)

root@Ice-***:/usr/local/mysql# bin/mysqld_safe --user=mysql &

敲回車

root@Ice-***:/usr/local/mysql# /usr/local/mysql/bin/mysql -uroot -p

Enter password: 
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.18

Copyright (c) 2000, 2017, 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;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql> 

10\重置密碼

mysql> SET PASSWORD = PASSWORD('newpasswd');
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
mysql> quit
Bye

11\設(shè)置開(kāi)機(jī)啟動(dòng)

root@Ice-***:/usr/local/mysql# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
root@Ice-***:/usr/local/mysql# chmod 755 /etc/init.d/mysqld

12\安裝mysql-server 和 mysql-client

root@Ice-***:~# apt-get install mysql-server
root@Ice-***:~# apt-get install mysql-client
root@Ice-***:~# apt-get install libmysqlclient-dev


E: Sub-process /usr/bin/dpkg returned an error code (1)

解決辦法:

1.$ sudo mv /var/lib/dpkg/info /var/lib/dpkg/info_old //現(xiàn)將info文件夾更名 
2.$ sudo mkdir /var/lib/dpkg/info //再新建一個(gè)新的info文件夾 
3.$ sudo apt-get update,  
   $ apt-get -f install //修復(fù)依賴樹(shù)
4.$ sudo mv /var/lib/dpkg/info/* /var/lib/dpkg/info_old //執(zhí)行完上一步操作后會(huì)在新的info文件夾下生成一些文件,現(xiàn)將這些文件全部移到info_old文件夾下 
5.$ sudo rm -rf /var/lib/dpkg/info //把自己新建的info文件夾刪掉 
6.$ sudo mv /var/lib/dpkg/info_old /var/lib/dpkg/info //把以前的info文件夾重新改回名字

最后,如果是Ubuntu系統(tǒng)可能無(wú)法向表中插入漢字,無(wú)法從表中查詢漢字..

解決辦法:

關(guān)閉數(shù)據(jù)庫(kù)服務(wù)

service mysql stop
~$ sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf

在[mysqld]下添加一行character_set_server=utf8
配置文件選段:

[mysqld]
#
# * Basic Settings
#
user = mysql
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
port = 3306
basedir = /usr
datadir = /var/lib/mysql
tmpdir = /tmp
lc-messages-dir = /usr/share/mysql
character_set_server=utf8 就是這一行,原來(lái)是沒(méi)有的,要手動(dòng)添加!
skip-external-locking
#


將上述文件拷貝至/etc/mysql/my.cnf

~$ sudo cp /etc/mysql/mysql.conf.d/mysqld.cnf /etc/mysql/my.cnf

重啟數(shù)據(jù)庫(kù)服務(wù)

~$ /etc/init.d/mysql restart

如果查看字符集能得到如下結(jié)果就說(shuō)明成功了.

mysql> show variables like 'collation_%';
+----------------------+-----------------+
| Variable_name | Value |
+----------------------+-----------------+
| collation_connection | utf8_general_ci |
| collation_database | utf8_general_ci |
| collation_server | utf8_general_ci |
+----------------------+-----------------+
3 rows in set (0.00 sec)

mysql> show variables like 'character_set_%';
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.01 sec)

您可能感興趣的文章:

  • linux下安裝apache與php;Apache+PHP+MySQL配置攻略
  • linux正確重啟MySQL的方法
  • Linux下安裝mysql-5.6.4 的圖文教程
  • linux下講解MySQL安裝與登錄方法
  • linux下mysql提示"mysql deamon failed to start"錯(cuò)誤的解決方法
  • linux mysql 報(bào)錯(cuò):MYSQL:The server quit without updating PID file
  • Linux下MySQL安裝配置 MySQL配置參數(shù)詳解
  • 在linux中導(dǎo)入sql文件的方法分享(使用命令行轉(zhuǎn)移mysql數(shù)據(jù)庫(kù))
  • Linux下安裝與使用MySQL詳細(xì)介紹
  • mysql 5.7.13 安裝配置方法圖文教程(linux)
  • linux mysql5.6版本的安裝配置過(guò)程
  • 聲明:本網(wǎng)頁(yè)內(nèi)容旨在傳播知識(shí),若有侵權(quán)等問(wèn)題請(qǐng)及時(shí)與本網(wǎng)聯(lián)系,我們將在第一時(shí)間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

    文檔

    Linux下安裝配置MySQL

    Linux下安裝配置MySQL:系統(tǒng):Ubuntu 16.04LTS 1\官網(wǎng)下載mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz 2\建立工作組: $su #groupadd mysql #useradd -r -g mysql mysql 3\創(chuàng)建目錄 #mkdir /usr/local/mysql #mkdir /usr/
    推薦度:
    標(biāo)簽: 設(shè)置 安裝 安裝包
    • 熱門焦點(diǎn)

    最新推薦

    猜你喜歡

    熱門推薦

    專題
    Top