1. 程式人生 > >mysql-rpm包安裝

mysql-rpm包安裝

mon option 用戶 全部 https nat rev als event

數據庫 關系型數據庫(RDBMS):oracle mysql db2 sql server sybase... 優點:容易理解、方便使用、數據一致、讀寫實時 數據一致:事務 要麽全部成功;要麽全部失敗; 在我們數據庫中一個事務是由很多條sql語句組成,要麽全部執行成功,要麽全部失敗;這樣才能保證數據的一致性 應用場景:1、對數據的一致性要求比較高(銀行的交易系統)2、對數據的實時性要求較高 非關系型數據:【nosql】 Mongdb redis memcahe .. https://db-engines.com/en/ranking Mysql數據庫的安裝: 1、通過二進制包的方式安裝 rpm:xxx.el6.x86_64.rpm glibc:Linux所有版本通用的一個二進制的軟件包。也是C的運行庫,幾乎所有的linux系統最底層的api接口,都會依賴glibc。 優點:方便安裝 缺點:不能自定義 2、源碼包安裝 xxx.tar.gz 三步曲 (配置編譯安裝) 優點:靈活,可以自定義 缺點:比較麻煩 3、構建自己的rpm包 優點:根據需求定址自己的rpm包,後續方便安裝 缺點:前期的構建時間長,而且麻煩 安裝: 1、使用rpm包安裝 1)redhat 自己的mysqlrpm包 mysql.x86_64 5.1.71-1.el6 mysql-bench.x86_64 5.1.71-1.el6 mysql-connector-java.noarch 1:5.1.17-6.el6 mysql-connector-odbc.x86_64 5.1.5r1144-7.el6 mysql-devel.i686 5.1.71-1.el6 mysql-devel.x86_64 5.1.71-1.el6 mysql-libs.i686 5.1.71-1.el6 mysql-server.x86_64 5.1.71-1.el6 mysql-test.x86_64 5.1.71-1.el6 php-mysql.x86_64 5.3.3-26.el6 # rpm -ql mysql-server /etc/logrotate.d/mysqld 日誌輪轉文件 /etc/rc.d/init.d/mysqld 啟動腳本 /var/lib/mysql mysql的默認數據根目錄 /var/log/mysqld.log 日誌文件 /var/run/mysqld mysql進程目錄 # rpm -ql mysql /usr/bin/mysql 客戶端命令 /usr/bin/mysqladmin /usr/bin/mysqlbinlog /usr/bin/mysqlcheck /usr/bin/mysqldump /usr/bin/mysqlimport /usr/bin/mysqlshow 啟動服務: # /etc/rc.d/init.d/mysqld start # service mysql start (啟動過程:) Initializing MySQL database: Installing MySQL system tables... OK Filling help tables... OK ------以上2個ok說明數據庫初始化完畢 To start mysqld at boot time you have to copy support-files/mysql.server to the right place for your system PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER ! To do so, start the server, then issue the following commands: /usr/bin/mysqladmin -u root password ‘new-password‘ /usr/bin/mysqladmin -u root -h node1.uplook.com password ‘new-password‘ Alternatively you can run: /usr/bin/mysql_secure_installation which will also give you the option of removing the test databases and anonymous user created by default. This is strongly recommended for production servers. See the manual for more instructions. You can start the MySQL daemon with: cd /usr ; /usr/bin/mysqld_safe & You can test the MySQL daemon with mysql-test-run.pl cd /usr/mysql-test ; perl mysql-test-run.pl Please report any problems with the /usr/bin/mysqlbug script! [ OK ] Starting mysqld: [ OK ] 後續配置: # /usr/bin/mysql_secure_installation 安全配置 Change the root password? [Y/n] n ... skipping. Remove anonymous users? [Y/n] n ... skipping. Disallow root login remotely? [Y/n] n 生產環境中一般是不允許遠程訪問 ... skipping. Remove test database and access to it? [Y/n] y Reload privilege tables now? [Y/n] y # netstat -nltp|grep 3306 tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 4739/mysqld # mysql -p123-----登錄mysql mysql> show databases 查看當前數據庫 -> ; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | +--------------------+ 2 rows in set (0.00 sec) information_schema數據庫:對象數據信息庫,一般保存的是其他數據庫的相關信息;裏面只有一個只讀的表,實際上是一個視圖,不是基本表,無法看到任何的相關文件 mysql數據庫:核心的庫 test庫:測試庫 ------------------------------------------------------------------------------------------------------------- 後續密碼設置: 1、直接使用客戶端工具設置密碼 # mysqladmin -u root password ‘123‘ 設置新密碼(第一次設置密碼) # mysqladmin -u root password ‘newpass‘ -p123 重新設置密碼 # mysqladmin -u root password ‘mysql‘ -p ----(輸入passwd) 2、使用sql語句直接更新表信息、 進入mysql: mysql> update user set password=password(456) where user=‘root‘ and host=‘localhost‘; mysql> flush privileges; 刷新授權表 或者 mysql> flush privileges; 刷新授權表 mysql> set password for ‘root‘@‘localhost‘=password(‘123‘); 不需要刷新授權表 3、不知道原來的密碼 1)修改配置文件 /etc/mysql/my.cnf /etc/my.cnf ~/.my.cnf (如果以上配置文件有沖突,那麽以最後讀取到的為主) vim /etc/my.cnf [mysqld] skip-grant-tables 跳過授權表 datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock user=mysql # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 [mysqld_safe] log-error=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid #pid-file=/var/lib/mysql/mysqld.pid 2)直接在後臺安全進程啟動mysql # /usr/bin/mysqld_safe --skip-grant-tables & 初始化: # /usr/bin/mysql_install_db --user=mysql --defaults-file=/etc/my.cnf 2、安裝mysql AB 官方的rpm包 MySQL-server-5.6.19-1.el6.x86_64.rpm MySQL-client-5.6.19-1.el6.x86_64.rpm MySQL-devel-5.6.19-1.el6.x86_64.rpm MySQL-embedded-5.6.19-1.el6.x86_64.rpm MySQL-shared-5.6.19-1.el6.x86_64.rpm MySQL-shared-compat-5.6.19-1.el6.x86_64.rpm MySQL-test-5.6.19-1.el6.x86_64.rpm 安裝前: # rpm -e mysql-server mysql mysql-libs --nodeps # rm -rf /var/lib/mysql/* # cd /var/lib/mysql/ # rpm -ivh MySQL-server-5.6.19-1.el6.x86_64.rpm # cat ~/.mysql_secret ---------> 初始密碼 # mysql_secure_installation ... 安裝過程出現的問題解決: 錯誤提示:找不到/var/lib/mysql/mysql.sock 解決: # service mysql start 3306監聽 註意:pid文件和sock文件是在服務啟動後產生的; 錯誤: mysql> show databases; ERROR 1820 (HY000): You must SET PASSWORD before executing this statement mysql> set password for ‘root‘@‘localhost‘=password(‘111‘); mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | +--------------------+ performance_schema:數據庫是mysql 5.5版本以後有的,收集操作系統性能相關的信息 mysql客戶端工具: -u:指定用戶 -S:指定sock文件 -h:指定主機(ip|主機名) -e:外部執行sql -P:指定端口 -p:指定密碼 # mysql -p (默認是root用戶從localhost登錄) # mysql -u xxx -P xxx -p 說明: -p參數後面跟的密碼不能有空格;如果有空格就意味者訪問的是參數後面的數據庫 # mysql -p 123 Enter password: ERROR 1049 (42000): Unknown database ‘123‘ # mysql -uroot -e ‘show databases;‘ -p Enter password: +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | +--------------------+ 查看:>show databases -----查看數據庫的列表 >use information_schema mysql----進入 >show tables >select *from FILES

mysql-rpm包安裝