linux安裝mysql

來源:互聯網
上載者:User

標籤:http   使用   os   io   strong   檔案   資料   for   

1.下載MySQL
我下載的版本:mysql-5.6.4.tar.gz

2.安裝之前先卸載CentOS內建的MySQL
[[email protected] ~]# yum remove mysql

3.編譯安裝Cmake
下載cmake源碼包:http://www.cmake.org/files/v2.8/cmake-2.8.4.tar.gz

從共用目錄移至usr目錄
[[email protected] ~]# mv /home/user/cmake-2.8.4.tar.gz /usr/cmake-2.8.4.tar.gz
[[email protected] ~]# cd /usr

解壓並安裝cmake
[[email protected] usr]# tar xzvf cmake-2.8.4.tar.gz
[[email protected] usr]# cd cmake-2.8.4
[[email protected] cmake-2.8.4]# ./bootstrap

---------------------------------------------
CMake 2.8.4, Copyright 2000-2009 Kitware, Inc.
---------------------------------------------
Error when bootstrapping CMake:
Cannot find appropriate C compiler on this system.
Please specify one using environment variable CC.
See cmake_bootstrap.log for compilers attempted.

---------------------------------------------
Log of errors: /usr/local/src/cmake-2.8.4/Bootstrap.cmk/cmake_bootstrap.log
---------------------------------------------
報錯:缺少C的編譯器
解決辦法:安裝gcc編譯器
[[email protected] ~]# yum install gcc

繼續安裝Cmake
[[email protected] cmake-2.8.4]# ./bootstrap

---------------------------------------------
CMake 2.8.4, Copyright 2000-2009 Kitware, Inc.
C compiler on this system is: cc
---------------------------------------------
Error when bootstrapping CMake:
Cannot find appropriate C++ compiler on this system.
Please specify one using environment variable CXX.
See cmake_bootstrap.log for compilers attempted.
---------------------------------------------
Log of errors: /usr/local/src/cmake-2.8.4/Bootstrap.cmk/cmake_bootstrap.log
---------------------------------------------
報錯:缺少C++編譯器 
解決辦法:安裝gcc-c++編譯器
[[email protected] ~]# yum install gcc-c++

再次安裝
[[email protected] cmake-2.8.4]# ./bootstrap 
沒有報錯,編譯安裝
[[email protected] cmake-2.8.4]# gmake
[[email protected] cmake-2.8.4]# gmake install

 

 

4.正式開始安裝MySQL
添加MySQL使用者和使用者組
[[email protected] ~]# groupadd mysql
[[email protected] ~]# useradd -g mysql mysql

MySQL源碼包從共用資料夾移至/usr並解壓
[[email protected] ~]# mv /home/user/mysql-5.6.4.tar.gz /usr/mysql-5.6.4.tar.gz
[[email protected] usr]# tar xzvf mysql-5.6.4.tar.gz
[[email protected] usr]# cd mysql-5.6.4

Cmake運行
[[email protected] mysql-5.5.22]# cmake .

開始編譯安裝
[[email protected] mysql-5.5.22]# make && make install

進入安裝目錄,將程式二進位的所有權改為root,資料目錄的說有權改為mysql使用者,更新授權表
[[email protected] mysql-5.5.22]# cd /usr/local/mysql/
[[email protected] mysql]# chown -R root .
[[email protected] mysql]# chown -R mysql .
[[email protected] mysql]# chgrp -R mysql .
[[email protected] mysql]# scripts/mysql_install_db --user=mysql

 

安全啟動MySQL(預設密碼為空白)
[[email protected] mysql]# ./bin/mysqld_safe --user=mysql&

source /etc/profile

報錯:

120908 00:16:25 mysqld_safe Logging to ‘/usr/local/mysql/data/CentOS.err‘.
120908 00:16:26 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data

解決方案:
[[email protected] ~]# cd /usr/local/mysql/data

[[email protected] data]# ls -l
總用量 29744
-rw-rw---- 1 mysql root 1585 9月 8 00:16 CentOS.err
-rw-rw---- 1 mysql mysql 6 9月 8 00:16 CentOS.pid
-rw-rw---- 1 mysql mysql 18874368 9月 8 00:16 ibdata1
-rw-rw---- 1 mysql mysql 5242880 9月 8 00:16 ib_logfile0
-rw-rw---- 1 mysql mysql 5242880 9月 8 00:16 ib_logfile1
drwxr-xr-x 2 mysql mysql 4096 9月 8 00:14 mysql
-rw-rw---- 1 mysql mysql 27293 9月 8 00:14 mysql-bin.000001
-rw-rw---- 1 mysql mysql 1031892 9月 8 00:14 mysql-bin.000002
-rw-rw---- 1 mysql mysql 107 9月 8 00:16 mysql-bin.000003
-rw-rw---- 1 mysql mysql 57 9月 8 00:16 mysql-bin.index
drwx------ 2 mysql mysql 4096 9月 8 00:14 performance_schema
drwxr-xr-x 2 mysql mysql 4096 9月 8 00:08 test


[[email protected] data]# chgrp -R mysql CentOS.err
[[email protected] data]# ls -l
總用量 29736
-rw-rw---- 1 mysql mysql 1585 9月 8 00:16 CentOS.err
-rw-rw---- 1 mysql mysql 6 9月 8 00:16 CentOS.pid
-rw-rw---- 1 mysql mysql 18874368 9月 8 00:16 ibdata1
-rw-rw---- 1 mysql mysql 5242880 9月 8 00:16 ib_logfile0
-rw-rw---- 1 mysql mysql 5242880 9月 8 00:16 ib_logfile1
drwxr-xr-x 2 mysql mysql 4096 9月 8 00:14 mysql
-rw-rw---- 1 mysql mysql 27293 9月 8 00:14 mysql-bin.000001
-rw-rw---- 1 mysql mysql 1031892 9月 8 00:14 mysql-bin.000002
-rw-rw---- 1 mysql mysql 107 9月 8 00:16 mysql-bin.000003
-rw-rw---- 1 mysql mysql 57 9月 8 00:16 mysql-bin.index
drwx------ 2 mysql mysql 4096 9月 8 00:14 performance_schema
drwxr-xr-x 2 mysql mysql 4096 9月 8 00:08 test

 

 

 

配置使用者
MySQL啟動成功後,root預設沒有密碼,我們需要設定root密碼。
設定之前,我們需要先設定PATH,要不不能直接調用mysql
修改/etc/profile檔案,在檔案末尾添加

[[email protected] mysql]#vi /etc/profile

複製代碼代碼如下:
PATH=/usr/local/mysql/bin:$PATH
export PATH

關閉檔案,運行下面的命令,讓配置立即生效

複製代碼代碼如下:
[[email protected] mysql]# source /etc/profile


串連本機MySQL
[[email protected] mysql]#mysql –u root –p
提示輸入password,預設為空白,按Enter即可

中斷連線
mysql>exit;

為root賬戶設定密碼
[[email protected] mysql]# mysqladmin -u root password 123456
Enter Password:123456

 

 

設定選項檔案,將設定檔拷貝到/etc下
[[email protected] mysql]# cp support-files/my-medium.cnf /etc/mysql.cnf

 

設定開機自啟動
[[email protected] mysql]# cp support-files/mysql.server /etc/init.d/mysql
[[email protected] mysql]# chmod +x /etc/init.d/mysql 
[[email protected] mysql]# chkconfig mysql on
 

 

通過服務來啟動和關閉Mysql
[[email protected] ~]# service mysql start
[[email protected] ~]# service mysql stop

5.安裝設定完畢,之後使用只需啟動-串連-斷開-關閉,命令如下:
[[email protected] mysql]# service mysql start
Starting MySQL.. [確定]

 


[[email protected] mysql]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.22 Source distribution

Copyright (c) 2000, 2011, 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.07 sec)

mysql> exit;
Bye
[[email protected] mysql]# service mysql stop
Shutting down MySQL. [確定]

6.其它:
查看進程命令 ps –ef|grep mysqld
kill進程命令 kill –9 進程號

 

 

  


編譯mysql出現CMake Error at cmake/readline.cmake:83 (MESSAGE) 

 

-- Could NOT find Curses  (missing:  CURSES_LIBRARY CURSES_INCLUDE_PATH)
CMake Error at cmake/readline.cmake:83 (MESSAGE):
  Curses library not found.  Please install appropriate package,
 
remove CMakeCache.txt and rerun cmake.On Debian/Ubuntu, package name is libncurses5-dev, on Redhat and derivates it is ncurses-devel.
Call Stack (most recent call first):
  cmake/readline.cmake:127 (FIND_CURSES)
  cmake/readline.cmake:217 (MYSQL_USE_BUNDLED_LIBEDIT)
  CMakeLists.txt:257 (MYSQL_CHECK_READLINE) 
 
-- Configuring incomplete, errors occurred!
 
該報錯原因是未安裝ncurses-devel,運行下面命令
第一步:安裝
#yum -y install ncurses-devel
 
第二步:刪除CMakeCache.txt
通過find命令找到所有CMakeCache.txt文檔的位置
#find / -name CMakeCache.txt
然後全部刪除:
# rm -rf /usr/local/src/cmake-2.8.6/Tests/Complex/Cache/CMakeCache.txt
# rm -rf /usr/local/src/cmake-2.8.6/Tests/ComplexOneConfig/Cache/CMakeCache.txt
# rm -rf /usr/local/src/cmake-2.8.6/Tests/ComplexRelativePaths/Cache/CMakeCache.txt
# rm -rf /usr/local/src/mysql-5.5.18/CMakeCache.txt

 

 


解決方案: 
 
1. 改表法。 
 
可能是你的帳號不允許從遠程登陸,只能在localhost。這個時候只要在localhost的那台電腦,登入mysql後,更改 "mysql" 資料庫裡的 "user" 表裡的 "host" 項,從"localhost"改稱"%"
 
mysql -u root -pvmwaremysql>use mysql;   www.2cto.com  
 
mysql>update user set host = ‘%‘ where user = ‘root‘; 
 
mysql>select host, user from user; 
 
2. 授權法。 
 
例如,你想myuser使用mypassword從任何主機串連到mysql伺服器的話。 
 
GRANT ALL PRIVILEGES ON *.* TO ‘myuser‘@‘%‘ IDENTIFIED BY ‘mypassword‘ WITH GRANT OPTION;
 
FLUSH   PRIVILEGES; 
 
如果你想允許使用者myuser從ip為192.168.1.6的主機串連到mysql伺服器,並使用mypassword作為密碼 
 
GRANT ALL PRIVILEGES ON *.* TO ‘myuser‘@‘192.168.1.3‘ IDENTIFIED BY ‘mypassword‘ WITH GRANT OPTION;   www.2cto.com  
 
FLUSH   PRIVILEGES; 
 
如果你想允許使用者myuser從ip為192.168.1.6的主機串連到mysql伺服器的dk資料庫,並使用mypassword作為密碼 
 
GRANT ALL PRIVILEGES ON dk.* TO ‘myuser‘@‘192.168.1.3‘ IDENTIFIED BY ‘mypassword‘ WITH GRANT OPTION; 
 
FLUSH   PRIVILEGES;

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.