大資料之MySQL部署
啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊??????????? 剛剛沒有儲存,得重寫,抓狂×3 終於補完了Linux命令,今天繼續補MySQL??????????? MySQL環境部署,內容很多?????????????
一、部署
最簡單的方式是rpm包部署: 優點:部署簡單; 缺點:路徑(目錄)固化。 yum install mysql-server yum install mysql-client 企業裡面最常用的是:二進位制部署: 優點:路徑(目錄)定製化; 缺點:部署複雜。
二、二進位制部署如何進行
先將MySQL和JDK安裝包上傳到/usr/local目錄
在進行檔案傳輸的時候,可以使用sftp (alt+p)方式進行傳輸檔案,也經常使用rz命令進行圖形化的方式傳輸檔案。 當rz命令無效時,執行如下指令進行安裝即可:yum install lrzsz -y(免輸)
1、將JDK上傳完之後解壓:[[email protected] java]# tar -xzvf jdk-8u45-linux-x64.gz 2、修改使用者和使用者組(坑):[[email protected] java]# ll total 169216 drwxr-xr-x 8 uucp 143 4096 Apr 11 2015 jdk1.8.0_45(修改此使用者和使用者組) -rw-r–r-- 1 root root 173271626 Sep 16 18:46 jdk-8u45-linux-x64.gz [[email protected] java]# chown -R root:root jdk1.8.0_45(修改命令)
export PATH=$ JAVA_HOME/bin:$ RZDATA_HOME/bin:$PATH 儲存退出 4、生效環境變數: [[email protected] java]# source /etc/profile [[email protected] java]# which java /usr/java/jdk1.8.0_45/bin/java [[email protected]
if user mysqladmin is existing,please execute the following command of usermod.
##[[email protected] local]]# usermod -u 514 -g dba -G root -d /usr/local/mysql mysqladmin
copy 環境變數配置檔案至mysqladmin使用者的home目錄中,為了以下步驟配置個人環境變數
[[email protected] local]# cp /etc/skel/.* /usr/local/mysql [[email protected] local]# cp /etc/skel/.* /usr/local/mysql cp: omitting directory `/etc/skel/.’
cp: omitting directory `/etc/skel/…’ (5)Create /etc/my.cnf(640) #defualt start: /etc/my.cnf->/etc/mysql/my.cnf->SYSCONFDIR/my.cnf->$MYSQL_HOME/my.cnf-> --defaults-extra-file->~/my.cnf [[email protected] mysql]# cd /etc/ [[email protected] etc]# touch my.cnf [[email protected] etc]# vi my.cnf (dG刪除已有的內容,黏貼以下內容) [client] port = 3306 socket = /usr/local/mysql/data/mysql.sock
[mysqld] port = 3306 socket = /usr/local/mysql/data/mysql.sock
skip-external-locking key_buffer_size = 256M sort_buffer_size = 2M read_buffer_size = 2M read_rnd_buffer_size = 4M query_cache_size= 32M max_allowed_packet = 16M myisam_sort_buffer_size=128M tmp_table_size=32M
table_open_cache = 512 thread_cache_size = 8 wait_timeout = 86400 interactive_timeout = 86400 max_connections = 600
#Try number of CPU’s*2 for thread_concurrency thread_concurrency = 32
#isolation level and default engine default-storage-engine = INNODB transaction-isolation = READ-COMMITTED
server-id = 1 basedir = /usr/local/mysql datadir = /usr/local/mysql/data pid-file = /usr/local/mysql/data/hostname.pid
#open performance schema log-warnings sysdate-is-now
binlog_format = MIXED log_bin_trust_function_creators=1 log-error = /usr/local/mysql/data/hostname.err log-bin=/usr/local/mysql/arch/mysql-bin #other logs #general_log =1 #general_log_file = /usr/local/mysql/data/general_log.err #slow_query_log=1 #slow_query_log_file=/usr/local/mysql/data/slow_log.err
#for replication slave #log-slave-updates #sync_binlog = 1
#for innodb options innodb_data_home_dir = /usr/local/mysql/data/ innodb_data_file_path = ibdata1:500M:autoextend innodb_log_group_home_dir = /usr/local/mysql/arch innodb_log_files_in_group = 2 innodb_log_file_size = 200M
innodb_buffer_pool_size = 2048M innodb_additional_mem_pool_size = 50M innodb_log_buffer_size = 16M
innodb_lock_wait_timeout = 100 #innodb_thread_concurrency = 0 innodb_flush_log_at_trx_commit = 1 innodb_locks_unsafe_for_binlog=1
#innodb io features: add for mysql5.5.8 performance_schema innodb_read_io_threads=4 innodb-write-io-threads=4 innodb-io-capacity=200 #purge threads change default(0) to 1 for purge innodb_purge_threads=1 innodb_use_native_aio=on
#case-sensitive file names and separate tablespace innodb_file_per_table = 1 lower_case_table_names=1
[mysqldump] quick max_allowed_packet = 16M
[mysql] no-auto-rehash
[mysqlhotcopy] interactive-timeout
[myisamchk] key_buffer_size = 256M sort_buffer_size = 256M read_buffer = 2M write_buffer = 2M 儲存退出 修改: innodb_buffer_pool_size = 1024M 不正常退出會產生swp檔案,刪除:rm .my.cnf.swp -f (6)chown and chmod privileges and try first install [[email protected] etc]# chown mysqladmin:dba /etc/my.cnf [[email protected] etc]# chmod 640 /etc/my.cnf [[email protected] etc]# ll my.cnf -rw-r----- 1 mysqladmin dba 2218 Sep 17 23:34 my.cnf [[email protected] etc]# chown -R mysqladmin:dba /usr/local/mysql [[email protected] etc]# chmod -R 755 /usr/local/mysql [[email protected] etc]# su - mysqladmin [[email protected] ~]$ pwd /usr/local/mysql 建立binlog(歸檔)檔案 [[email protected] ~]$ mkdir arch [[email protected] ~]$ scripts/mysql_install_db [[email protected] local]# cat /proc/version (看版本) Linux version 2.6.32-696.6.3.el6.x86_64 ([email protected]) (gcc version 4.4.7 20120313 (Red Hat 4.4.7-18) (GCC) ) #1 SMP Wed Jul 12 14:17:22 UTC 2017 [[email protected] local]# rpm -qa |grep gcc gcc-4.4.7-18.el6.x86_64 libgcc-4.4.7-18.el6.x86_64 [[email protected] local]# yum -y install libaio Loaded plugins: fastestmirror Setting up Install Process Loading mirror speeds from cached hostfile base | 3.7 kB 00:00 epel | 3.2 kB 00:00 extras | 3.4 kB 00:00 updates | 3.4 kB 00:00 Package libaio-0.3.107-10.el6.x86_64 already installed and latest version Nothing to do
(7)Again install [[email protected] ~]$ scripts/mysql_install_db --user=mysqladmin --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data WARNING: The host ‘hadoopooo’ could not be looked up with /usr/local/mysql/bin/resolveip. This probably means that your libc libraries are not 100 % compatible with this binary MySQL version. The MySQL daemon, mysqld, should work normally with the exception that host name resolving will not work. This means that you should use IP addresses instead of hostnames when specifying MySQL privileges !
Installing MySQL system tables…2018-09-17 23:55:46 0 [Warning] ‘THREAD_CONCURRENCY’ is deprecated and will be removed in a future release. 2018-09-17 23:55:46 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2018-09-17 23:55:46 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap. 2018-09-17 23:55:46 0 [Note] /usr/local/mysql/bin/mysqld (mysqld 5.6.41-log) starting as process 15700 … OK
Filling help tables…2018-09-17 23:55:48 0 [Warning] ‘THREAD_CONCURRENCY’ is deprecated and will be removed in a future release. 2018-09-17 23:55:48 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2018-09-17 23:55:48 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap. 2018-09-17 23:55:48 0 [Note] /usr/local/mysql/bin/mysqld (mysqld 5.6.41-log) starting as process 15723 … 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/local/mysql/bin/mysqladmin -u root password ‘new-password’ /usr/local/mysql/bin/mysqladmin -u root -h hadoopooo password ‘new-password’
Alternatively you can run:
/usr/local/mysql/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/local/mysql/bin/mysqld_safe &
You can test the MySQL daemon with mysql-test-run.pl
The latest information about MySQL is available on the web at
Support MySQL by buying support/licenses at http://shop.mysql.com
WARNING: Found existing config file /usr/local/mysql/my.cnf on the system. Because this file might be in use, it was not replaced, but was used in bootstrap (unless you used --defaults-file) and when you later start the server. The new default config file was created as /usr/local/mysql/my-new.cnf, please compare it with your file and take the changes you need.
WARNING: Default config file /etc/my.cnf exists on the system This file will be read by default by the MySQL server If you do not want to use this, either remove it, or use the –defaults-file argument to mysqld_safe when starting the server
(8)Configure mysql service and boot auto start(開機自啟動) [[email protected] ~]# cd /usr/local [[email protected] local]# cd /usr/local/mysql [[email protected] mysql]# cp support-files/mysql.server /etc/rc.d/init.d/mysql (#將服務檔案拷貝到init.d下,並重命名為mysql) [[email protected] mysql]# chmod +x /etc/rc.d/init.d/mysql (#賦予可執行許可權) [[email protected] mysql]# chkconfig --add mysql (#新增服務) [[email protected] mysql]# chkconfig mysql on [[email protected] mysql]# vi /etc/rc.local #!/bin/sh
#This script will be executed after all the other init scripts. #You can put your own initialization stuff in here if you don’t #want to do the full Sys V style init stuff.
touch /var/lock/subsys/local
su - mysqladmin -c “/etc/init.d/mysql start --federated”(新增這組命令)
(9)Start mysql and to view process and listening [[email protected] mysql]# su - mysqladmin [[email protected] ~]$ pwd /usr/local/mysql [[email protected] ~]$ rm -rf my.cnf [[email protected] ~]$ which mysqld_safe ~/bin/mysqld_safe [[email protected] ~]$ vi .bash_profile #.bash_profile
#Get the aliases and functions if [ -f ~/.bashrc ]; then . ~/.bashrc fi
#User specific environment and startup programs export MYSQL_HOME=/usr/local/mysql export PATH=$ MYSQL_HOME/bin:$PATH
[[email protected] ~]# cd /usr/local [[email protected] local]# cd mysql [[email protected] mysql]# su - mysqladmin [[email protected] ~]$ echo $ MYSQL_HOME /usr/local/mysql [[email protected] ~]$ mysqld_safe &(enter後 enter) [[email protected] ~]$ ps -ef|grep mysql [[email protected] ~]$ netstat -tulnp | grep 15866 (Not all processes could be identified, non-owned process info will not be shown, you would have to be root to see it all.) [[email protected] ~]# netstat -tulnp | grep mysql tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 16509/mysqld
(10)Login mysql [[email protected] ~]$ mysql(直接輸入mysql) 然後輸入show databases;
(11)Update password and Purge user mysql> use mysql;(輸入) Database changed mysql> show tables;(輸入) mysql> select user,password,host from user; (輸入) mysql> update user set password=password(‘123456’) where user=‘root’; Query OK, 4 rows affected (0.00 sec) Rows matched: 4 Changed: 4 Warnings: 0
mysql> select user,password,host from user; mysql> delete from user where user=’’; Query OK, 2 rows affected (0.00 sec)
mysql> select user,password,host from user; mysql> flush privileges; Query OK, 0 rows affected (0.00 sec)
(12)Configure .bash_profile #.bash_profile
#Get the aliases and functions if [ -f ~/.bashrc ]; then . ~/.bashrc fi
#User specific environment and startup programs export MYSQL_HOME=/usr/local/mysql export PATH=$ MYSQL_HOME/bin:$PATH
create database Sylviadb; grant all privileges on Sylviadb.* to [email protected]’%’ identified by ‘123456’; [[email protected] ~]$ mysql ERROR 1045 (28000): Access denied for user ‘root’@‘localhost’ (using password: NO) [[email protected] ~]$ mysql -uroot -p123456 Warning: Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 6 Server version: 5.6.41-log MySQL Community Server (GPL)
Copyright © 2000, 2018, 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> create database Sylviadb; Query OK, 1 row affected (0.00 sec)
mysql> show databases; ±-------------------+ | Database | ±-------------------+ | information_schema | | mysql | | performance_schema | | sylviadb | | test | ±-------------------+ 5 rows in set (0.00 sec) mysql> grant all privileges on Sylviadb.* to [email protected]’%’ identified by ‘123456’; Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges; Query OK, 0 rows affected (0.00 sec)
(13)下載dbeaver工具 對於雲主機,web介面防火牆規則,入站出站新增3306
未完待續。。。。。。。。。。
加油???
2018-9-24 18:00 Sylvia