Ubuntu下安裝MYSQL出現 E: 無法定位軟體包問題
阿新 • • 發佈:2018-12-27
首先用終端進行root登入:
sudo -i
再切換到/etc/apt/目錄下,執行:
cd /etc/apt/
- 第一步,備份官方的預設源
避免自己手賤操作失誤,重灌系統太費時間
cp /etc/apt/sources.list /etc/apt/sources.list.bak #此命令是備份該官方原始檔
Ubuntu 14.04.4官方預設更新源sources.list
# deb cdrom:[Ubuntu 14.04.4 LTS _Trusty Tahr_ - Release amd64 (20160217.1)]/ trusty main restricted # See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to # newer versions of the distribution. deb http://cn.archive.ubuntu.com/ubuntu/ trusty main restricted deb-src http://cn.archive.ubuntu.com/ubuntu/ trusty main restricted ## Major bug fix updates produced after the final release of the ## distribution. deb http://cn.archive.ubuntu.com/ubuntu/ trusty-updates main restricted deb-src http://cn.archive.ubuntu.com/ubuntu/ trusty-updates main restricted ## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu ## team. Also, please note that software in universe WILL NOT receive any ## review or updates from the Ubuntu security team. deb http://cn.archive.ubuntu.com/ubuntu/ trusty universe deb-src http://cn.archive.ubuntu.com/ubuntu/ trusty universe deb http://cn.archive.ubuntu.com/ubuntu/ trusty-updates universe deb-src http://cn.archive.ubuntu.com/ubuntu/ trusty-updates universe ## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu ## team, and may not be under a free licence. Please satisfy yourself as to ## your rights to use the software. Also, please note that software in ## multiverse WILL NOT receive any review or updates from the Ubuntu ## security team. deb http://cn.archive.ubuntu.com/ubuntu/ trusty multiverse deb-src http://cn.archive.ubuntu.com/ubuntu/ trusty multiverse deb http://cn.archive.ubuntu.com/ubuntu/ trusty-updates multiverse deb-src http://cn.archive.ubuntu.com/ubuntu/ trusty-updates multiverse ## N.B. software from this repository may not have been tested as ## extensively as that contained in the main release, although it includes ## newer versions of some applications which may provide useful features. ## Also, please note that software in backports WILL NOT receive any review ## or updates from the Ubuntu security team. deb http://cn.archive.ubuntu.com/ubuntu/ trusty-backports main restricted universe multiverse deb-src http://cn.archive.ubuntu.com/ubuntu/ trusty-backports main restricted universe multiverse deb http://security.ubuntu.com/ubuntu trusty-security main restricted deb-src http://security.ubuntu.com/ubuntu trusty-security main restricted deb http://security.ubuntu.com/ubuntu trusty-security universe deb-src http://security.ubuntu.com/ubuntu trusty-security universe deb http://security.ubuntu.com/ubuntu trusty-security multiverse deb-src http://security.ubuntu.com/ubuntu trusty-security multiverse ## Uncomment the following two lines to add software from Canonical's ## 'partner' repository. ## This software is not part of Ubuntu, but is offered by Canonical and the ## respective vendors as a service to Ubuntu users. # deb http://archive.canonical.com/ubuntu trusty partner # deb-src http://archive.canonical.com/ubuntu trusty partner ## This software is not part of Ubuntu, but is offered by third-party ## developers who want to ship their latest software. deb http://extras.ubuntu.com/ubuntu trusty main deb-src http://extras.ubuntu.com/ubuntu trusty main
Ubuntu 16.04官方預設更新源sources.list
#deb cdrom:[Ubuntu 16.04.1 LTS _Xenial Xerus_ - Release amd64 (20160719)]/ xenial main restricted # See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to # newer versions of the distribution. deb http://cn.archive.ubuntu.com/ubuntu/ xenial main restricted # deb-src http://cn.archive.ubuntu.com/ubuntu/ xenial main restricted ## Major bug fix updates produced after the final release of the ## distribution. deb http://cn.archive.ubuntu.com/ubuntu/ xenial-updates main restricted # deb-src http://cn.archive.ubuntu.com/ubuntu/ xenial-updates main restricted ## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu ## team, and may not be under a free licence. Please satisfy yourself as to ## your rights to use the software. Also, please note that software in ## universe WILL NOT receive any review or updates from the Ubuntu security ## team. deb http://cn.archive.ubuntu.com/ubuntu/ xenial universe # deb-src http://cn.archive.ubuntu.com/ubuntu/ xenial universe deb http://cn.archive.ubuntu.com/ubuntu/ xenial-updates universe # deb-src http://cn.archive.ubuntu.com/ubuntu/ xenial-updates universe
- 第二步,修改官方源為第三方源
sudo vim /etc/apt/sources.list
附贈網上多數人推薦的第三方源:
- 中科大源:
deb http://mirrors.ustc.edu.cn/ubuntu/ precise-updates main restricted deb-src http://mirrors.ustc.edu.cn/ubuntu/ precise-updates main restricted deb http://mirrors.ustc.edu.cn/ubuntu/ precise universe deb-src http://mirrors.ustc.edu.cn/ubuntu/ precise universe deb http://mirrors.ustc.edu.cn/ubuntu/ precise-updates universe deb-src http://mirrors.ustc.edu.cn/ubuntu/ precise-updates universe deb http://mirrors.ustc.edu.cn/ubuntu/ precise multiverse deb-src http://mirrors.ustc.edu.cn/ubuntu/ precise multiverse deb http://mirrors.ustc.edu.cn/ubuntu/ precise-updates multiverse deb-src http://mirrors.ustc.edu.cn/ubuntu/ precise-updates multiverse deb http://mirrors.ustc.edu.cn/ubuntu/ precise-backports main restricted universe multiverse deb-src http://mirrors.ustc.edu.cn/ubuntu/ precise-backports main restricted universe multiverse deb http://security.ubuntu.com/ubuntu precise-security main restricted deb-src http://security.ubuntu.com/ubuntu precise-security main restricted deb http://security.ubuntu.com/ubuntu precise-security universe deb-src http://security.ubuntu.com/ubuntu precise-security universe deb http://security.ubuntu.com/ubuntu precise-security multiverse deb-src http://security.ubuntu.com/ubuntu precise-security multiverse
- 搜狐源
deb http://mirrors.sohu.com/ubuntu/ precise-updates main restricted
deb-src http://mirrors.sohu.com/ubuntu/ precise-updates main restricted
deb http://mirrors.sohu.com/ubuntu/ precise universe
deb-src http://mirrors.sohu.com/ubuntu/ precise universe
deb http://mirrors.sohu.com/ubuntu/ precise-updates universe
deb-src http://mirrors.sohu.com/ubuntu/ precise-updates universe
deb http://mirrors.sohu.com/ubuntu/ precise multiverse
deb-src http://mirrors.sohu.com/ubuntu/ precise multiverse
deb http://mirrors.sohu.com/ubuntu/ precise-updates multiverse
deb-src http://mirrors.sohu.com/ubuntu/ precise-updates multiverse
deb http://mirrors.sohu.com/ubuntu/ precise-backports main restricted universe multiverse
deb-src http://mirrors.sohu.com/ubuntu/ precise-backports main restricted universe multiverse
- 網易源
deb http://mirrors.163.com/ubuntu/ precise-updates main restricted
deb-src http://mirrors.163.com/ubuntu/ precise-updates main restricted
deb http://mirrors.163.com/ubuntu/ precise universe
deb-src http://mirrors.163.com/ubuntu/ precise universe
deb http://mirrors.163.com/ubuntu/ precise-updates universe
deb-src http://mirrors.163.com/ubuntu/ precise-updates universe
deb http://mirrors.163.com/ubuntu/ precise multiverse
deb-src http://mirrors.163.com/ubuntu/ precise multiverse
deb http://mirrors.163.com/ubuntu/ precise-updates multiverse
deb-src http://mirrors.163.com/ubuntu/ precise-updates multiverse
deb http://mirrors.163.com/ubuntu/ precise-backports main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ precise-backports main restricted universe multiverse
阿里雲源
# deb cdrom:[Ubuntu 16.04 LTS _Xenial Xerus_ - Release amd64 (20160420.1)]/ xenial main restricted
deb-src http://archive.ubuntu.com/ubuntu xenial main restricted #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates universe
deb http://mirrors.aliyun.com/ubuntu/ xenial multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse #Added by software-properties
deb http://archive.canonical.com/ubuntu xenial partner
deb-src http://archive.canonical.com/ubuntu xenial partner
deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial-security universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-security multiverse
大家,有時候,需要把http改成https
然後,大家可以像我這樣,來做好備份,有時候,會因為網路問題,需要用到不同的源,好切換!
/etc/apt/sources.list #(比如,這是官方的源)
/etc/apt/sources.list.qinghua #(比如,這是清華的源)
/etc/apt/sources.list.zhongkeda #(比如,這是中科大的源)
/etc/apt/sources.list.sohu #(比如,這是搜狐的源)
/etc/apt/sources.list.wangyi #(比如,這是網易的源)
/etc/apt/sources.list.aliyun #(比如,這是阿里雲的源)
然後,需要用到哪個了,在比如,我需要用到清華源,則,
mv sources.list.qinghua sources.list
然後,把官方的源,暫時改為
mv sources.list sources.list.bak
儲存後之後回到命令列下執行命令:
apt-get update && apt-get upgrade && apt-get dist-upgrade
apt-get clean #刪除以下載的包
reboot #重新啟動
這樣應該就沒問題了
備註:
apt-get常用命令:
update – 取回更新的軟體包列表資訊
upgrade – 進行一次升級
install – 安裝新的軟體包(注:軟體包名稱是 libc6 而非 libc6.deb)
remove – 解除安裝軟體包
purge – 解除安裝並清除軟體包的配置
autoremove – 解除安裝所有自動安裝且不再使用的軟體包
dist-upgrade – 釋出版升級,見 apt-get(8)
dselect-upgrade – 根據 dselect 的選擇來進行升級
build-dep – 為原始碼包配置所需的編譯依賴關係
clean – 刪除所有已下載的包檔案
autoclean – 刪除已下載的舊包檔案
check – 核對以確認系統的依賴關係的完整性
source – 下載原始碼包檔案
download – 下載指定的二進位制包到當前目錄
changelog – 下載指定軟體包,並顯示其changelog
直接執行如下命令
sudo pip install MySQL-python
報如下錯誤
[email protected]:~$ sudo pip install MySQL-python
Downloading/unpacking MySQL-python
Downloading MySQL-python-1.2.5.zip (108kB): 108kB downloaded
Running setup.py (path:/tmp/pip_build_root/MySQL-python/setup.py) egg_info for package MySQL-python
sh: 1: mysql_config: not found
Traceback (most recent call last):
File "<string>", line 17, in <module>
File "/tmp/pip_build_root/MySQL-python/setup.py", line 17, in <module>
metadata, options = get_config()
File "setup_posix.py", line 43, in get_config
libs = mysql_config("libs_r")
File "setup_posix.py", line 25, in mysql_config
raise EnvironmentError("%s not found" % (mysql_config.path,))
EnvironmentError: mysql_config not found
Complete output from command python setup.py egg_info:
sh: 1: mysql_config: not found
解決方案是:
安裝python-dev
sudo apt-get install python-dev
然後再安裝
sudo apt-get install libmysqlclient-dev
最後安裝
sudo pip install MySQL-python
這樣就成功了。
下面是測試程式碼:
import MySQLdb
try:
conn = MySQLdb.connect(host='127.0.0.1',user='root',passwd='mysql',db='mydb',port=3306)
cur=conn.cursor()
cur.execute('insert into test values(0,"x0")')
conn.commit()
cur.close()
conn.close()
print "finish insert direct"
except MySQLdb.Error,e:
print e.args[1]