linux下jdk,mysql的部署
將jdk,mysql解壓
1注意解壓後,jdk的所屬使用者和使用者組可能要修改
[[email protected] java]# ll
total 169220
drwxr-xr-x. 8 uucp 143 4096 Apr 11 2015 jdk1.8.0_45
-rw-r--r--. 1 root root 173271626 Oct 24 17:25 jdk-8u45-linux-x64.gz
[[email protected] java]# chown -R root:root jdk1.8.0_45/
2配置java環境檔案/etc/profile,生效
[[email protected] java]# vi /etc/profile
[[email protected] java]# source /etc/profile
[[email protected] java]# which java
/usr/java/jdk1.8.0_45/bin/java
[[email protected] java]# java -version
java version "1.8.0_45"
3如果不熟悉環境,可以先檢查一下mysql有沒有被安裝過
[[email protected] java]# ps -ef|grep mysqld
root 2580 2428 0 16:09 pts/2 00:00:00 grep mysqld
[ [email protected] java]# rpm -qa | grep -i mysql
mysql-libs-5.1.71-1.el6.x86_64
4建立mysql使用者和組
[[email protected] local]# groupadd -g 101 dba
[[email protected] local]# useradd -u 514 -g dba -G root -d /usr/local/mysql mysqladmin
useradd: warning: the home directory already exists.
Not copying any file from skel directory into it.
[ [email protected] local]# id mysqladmin
uid=514(mysqladmin) gid=101(dba) groups=101(dba),0(root)
[[email protected] local]# usermod -u 514 -g dba -G root -d /usr/local/mysql mysqladmin
這裡先指定組名和對應的數字,514指的是建立的使用者id就是514,-g指定使用者的主組,-G副組,-d使用者建立之後的家目錄,使用者名稱稱叫做mysqladmin。這裡的警告是丟失環境變數檔案。
usermod是使用者已存在,修改一下。
5複製環境配置檔案到mysqladmin使用者的home目錄
[[email protected] local]# cp /etc/skel/.* /usr/local/mysql
cp: omitting directory `/etc/skel/.'
cp: omitting directory `/etc/skel/..'
cp: omitting directory `/etc/skel/.gnome2'
cp: omitting directory `/etc/skel/.mozilla'
6建立mysql配置檔案 /etc/my.cnf(640) 這個是許可權
[[email protected] local]# cd /etc/
[[email protected] etc]# touch my.cnf
[[email protected] etc]# vi my.cnf
注意:沒進入編輯模式貼上程式碼會丟失第一行頭幾個字母
[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
7修改配置檔案的使用者和使用者組
[[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 2219 Oct 28 18:51 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
8建立binlog檔案,並安裝libaio包
[[email protected] ~]$ mkdir arch
[[email protected] ~]$ yum -y install libaio
[[email protected] ~]$ scripts/mysql_install_db --user=mysqladmin --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
9設定mysql服務開機自啟動等
[[email protected] local]# cd /usr/local/mysql
[[email protected] mysql]# cp support-files/mysql.server /etc/rc.d/init.d/mysql
[[email protected] mysql]# chmod +x /etc/rc.d/init.d/mysql
[[email protected] mysql]# chkconfig --del mysql
[[email protected] mysql]# chkconfig --add mysql
[[email protected] mysql]# chkconfig mysql on
[[email protected] mysql]# vi /etc/rc.local
增加一句
su - mysqladmin -c "/etc/init.d/mysql start --federated"
10
刪了mysql下的my.cnf,因為我們配置的再etc目錄下
[[email protected] ~]$ rm -rf my.cnf
個人環境變數配置
[[email protected] ~]$ vi .bash_profile
裡面加入
export MySQL_HOME=/usr/local/mysql
export PATH=$ MYSQL_HOME/bin:$ PATH
退出重進
[[email protected] ~]$ exit
logout
There are stopped jobs.
[[email protected] ~]$ su -mysqladmin
su: invalid option -- 'y'
Try `su --help' for more information.
[[email protected] etc]# su - mysqladmin
[[email protected] ~]$ echo $ MYSQL_HOME
/usr/local/mysql
[[email protected] ~]$ mysqld_safe &
[1] 6337
查下程序埠號等
[[email protected] ~]$ ps -ef|grep mysqld
514 3448 1 0 Oct28 pts/2 00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe
[[email protected] ~]$ netstat -nlp|grep mysql
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
tcp 0 0 :::3306 :::* LISTEN 4091/mysqld
unix 2 [ ACC ] STREAM LISTENING 35117 4091/mysqld /usr/local/mysql/data/mysql.sock
[[email protected] mysql]# service mysql status
MySQL running (4091) [ OK ]
11
進入mysql
[[email protected] ~]$ mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.00 sec)
12
設定mysql賬號密碼
mysql> use mysql;
Database changed
檢視當前database
mysql> select database();
+------------+
| database() |
+------------+r
| mysql |
+------------+
看下有那些表
show tables;
mysql> select user,password,host from user;
+------+----------+-----------+
| user | password | host |
+------+----------+-----------+
| root | | localhost |
| root | | hadoop000 |
| root | | 127.0.0.1 |
| root | | ::1 |
| | | localhost |
| | | hadoop000 |
+------+----------+-----------+
6 rows in set (0.00 sec)
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;
+------+-------------------------------------------+-----------+
| user | password | host |
+------+-------------------------------------------+-----------+
| root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 | localhost |
mysql> delete from user where user='';
Query OK, 2 rows affected (0.00 sec)
重新整理許可權
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
重進要密碼
[[email protected] ~]$ mysql -uroot -p123456
建立db,給使用者賦予檢視db的許可權
mysql> create database ruozedb;
Query OK, 1 row affected (0.00 sec)
給ruoze這個使用者(可以通過什麼ip)賦予所有許可權爭對ruozedb裡的所有表
mysql> grant all privileges on ruozedb.* to [email protected]'127.0.0.1' identified by '123456';
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
注意這裡因為上面是127,這裡也要賦值
[[email protected] ~]$ mysql -uruoze -p123456 -h127.0.0.1
因為之後要去win裝mysql圖形化介面,所以這裡還是
這樣不管是哪裡的ip都能連資料庫
mysql> update user set host='%' where user='ruoze';
mysql> flush privileges;
用dbeaver連線報錯
檢視下,有問題
mysql> show grants for 'ruoze'@'%';
據說是由於修改ip導致不識別,需要配置網絡卡
window–VM8–>linux mysql
192.168.137.1
這裡需要補充一下知識,關於網段和普通ip,如果公司電腦的ip是變化的,可以將賬戶的ip設定成一個網段
172.16.110.100 mysql
‘user’@‘172.16.110.0’ 網段
注意生產連線的時候,-p之後不直接輸入密碼,會洩露。-p時密碼,-P是埠號。
刪了重搞
mysql> drop user [email protected]'%'
-> ;
mysql> grant all privileges on ruozedb.* to [email protected]'%' identified by '123456';