由于現(xiàn)在要用mysql,以前一直用oracle ,現(xiàn)在下個(gè)mysql都要翻墻下載,官方網(wǎng)站都下不了,選擇之后都是windows版本。
最后找了個(gè)外國(guó)網(wǎng)站:http://fossies.org/linux/misc/mysql-5.6.25-linux-glibc2.5-x86_64.tar.gz/ 下載了最新版本的:mysql-5.6.25-linux-glibc2.5-x86_64.tar.gz
查看當(dāng)前centos版本和內(nèi)核,位數(shù)。
[root@localhost ~]# cat /etc/redhat-release?。?etc/redhat-release配置文件用一行內(nèi)容來聲明 Red Hat 的名稱和版本號(hào)。 由 rc.local 使用.
CentOS release 6.5 (Final) ?。“l(fā)現(xiàn)我的是6.5版本。
[root@localhost ~]# cat /proc/version ?。?4位系統(tǒng)
Linux version 2.6.32-431.el6.x86_64 (mockbuild@c6b8.bsys.dev.centos.org) (gcc version 4.4.7 20120313 (Red Hat 4.4.7-4) (GCC) ) #1 SMP Fri Nov 22 03:15:09 UTC 2013
[root@localhost ~]# uname -a
Linux localhost.localdomain 2.6.32-431.el6.x86_64 #1 SMP Fri Nov 22 03:15:09 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
一、把mysql壓縮包上傳到/usr/mysql 目錄下面。安裝目錄選擇/usr/local/mysql。
然后在網(wǎng)上找一篇安裝mysql的文章,最后參考了http://blog.csdn.net/zhanngle/article/details/41042631
-------------------------------------------
二、按上面的文章安裝完之后
1、查詢當(dāng)前安裝的mysql版本
[root@localhost ~]# mysql -V
mysql Ver 14.14 Distrib 5.6.25, for linux-glibc2.5 (x86_64) using EditLine wrapper
進(jìn)入mysql、查看mysql版本
方法一:status;
方法二:select version();
2、Mysql啟動(dòng)、停止、重啟常用命令
a、啟動(dòng)方式
1、使用 service 啟動(dòng):
[root@localhost /]# service mysqld start (5.0版本是mysqld)
[root@szxdb etc]# service mysql start (5.5.7版本是mysql)
2、使用 mysqld 腳本啟動(dòng):
/etc/inint.d/mysqld start
3、使用 safe_mysqld 啟動(dòng):
safe_mysqld&
b、停止
1、使用 service 啟動(dòng):
service mysqld stop
2、使用 mysqld 腳本啟動(dòng):
/etc/inint.d/mysqld stop
3、mysqladmin shutdown
c、重啟
1、使用 service 啟動(dòng):
service mysqld restart
service mysql restart (5.5.7版本命令)
2、使用 mysqld 腳本啟動(dòng):
/etc/init.d/mysqld restart
三、賦予權(quán)限
(1)、創(chuàng)建用戶:
create user 'myuser'@'localhost' IDENTIFIED by '123456';
flush privileges;
(2)、創(chuàng)建數(shù)據(jù)庫(kù):
create database mydb;
flush privileges;
(3)、給用戶授權(quán)數(shù)據(jù)庫(kù)相關(guān)權(quán)限
grant all privileges on mydb.* to myuser@localhost identified by '123456';
flush privileges;
我用到的權(quán)限命令,簡(jiǎn)單說明,mydb為數(shù)據(jù)庫(kù)實(shí)例名,myuser為用戶名,后面對(duì)某個(gè)ip作對(duì)應(yīng)的權(quán)限控制。
grant 為賦予權(quán)限,revoke為撤銷權(quán)限,賦予權(quán)限完之后要用flush privileges; 來刷新生效。
1、grant all on mydb.* to 'myuser'@'192.168.1.6';
2、grant select on mydb.* to 'myuser'@'192.168.1.%';
3、revoke all on mydb.* from 'myuser'@'192.168.1.6';
查看用戶權(quán)限
show grants for 你的用戶
比如:
show grants for root@’localhost’;
mysql> use mysql;
Database changed
mysql> select user,host from user;
具體參考:http://www.cnblogs.com/llsun/archive/2013/08/06/3240963.html
四、導(dǎo)入數(shù)據(jù)問題解決
ERROR 2006 (HY000): MySQL server has gone away
No connection. Trying to reconnect...
1.執(zhí)行批量的MYSQL語(yǔ)句,例如備份恢復(fù)的時(shí)候,時(shí)間過長(zhǎng); 或者SQL語(yǔ)句過大或者語(yǔ)句中含有BLOB類似字段--我的是BLOB字段存放文件導(dǎo)致過大引起
對(duì)應(yīng):修改my.cnf中的wait_timeout和interactive_timeout變量
在一些不便修改的情形下,如租用的空間,可以采取sql語(yǔ)句修改,如何做呢?
(1)、如果是租用空間,無(wú)法修改數(shù)據(jù)庫(kù)參數(shù),那么臨時(shí)mysql語(yǔ)句設(shè)置,不過下次重新導(dǎo)入必須再設(shè)置:
#對(duì)當(dāng)前交互鏈接有效;
mysql>set wait_timeout = someIntValue;
#對(duì)后續(xù)起的交互鏈接有效;
mysql>set interactive_timeout = someIntValue;
mysql>set global max_allowed_packet=1000000000; ?。?/span>設(shè)置針對(duì)BLOB字段過大導(dǎo)入引起的問題
(2)、如果是自己的服務(wù)器,那么找到my.ini(windows下my.ini)文件,linux發(fā)現(xiàn)是/usr/local/mysql下的my.cnf文件。
添加一句max_allowed_packet=16M,如果不行將16M再加大
加大wait_timeout也可起一定作用
eg:
wait_timeout=2880000
interactive_timeout = 2880000
max_allowed_packet = 100M
應(yīng)用時(shí)記住重啟數(shù)據(jù)庫(kù)哦~~
除此之外,可能還有一些別的buffer_size的變量會(huì)影響到,也值得注意
例如
read_buffer_size
read_rnd_buffer_size
重啟后查詢
mysql> show variables like '%timeout';
+-----------------------------+----------+
| Variable_name | Value |
+-----------------------------+----------+
| connect_timeout | 10 |
| delayed_insert_timeout | 300 |
| innodb_flush_log_at_timeout | 1 |
| innodb_lock_wait_timeout | 50 |
| innodb_rollback_on_timeout | OFF |
| interactive_timeout | 2880000 |
| lock_wait_timeout | 31536000 |
| net_read_timeout | 30 |
| net_write_timeout | 60 |
| rpl_stop_slave_timeout | 31536000 |
| slave_net_timeout | 3600 |
| wait_timeout | 2880000 |
+-----------------------------+----------+
12 rows in set (0.00 sec)
mysql> show VARIABLES like '%max_allowed_packet%';
+--------------------------+------------+
| Variable_name | Value |
+--------------------------+------------+
| max_allowed_packet | 104857600 |
| slave_max_allowed_packet | 1073741824 |
+--------------------------+------------+
2 rows in set (0.00 sec)
五、安裝完之后訪問參考
http://blog.csdn.net/cuker919/article/details/44997923
六、啟動(dòng)應(yīng)用
啟動(dòng)應(yīng)用訪問發(fā)現(xiàn)應(yīng)用日志連接池報(bào):java.sql.SQLException: Access denied for user 'myuser'@'localhost' (using password: YES)
同時(shí)切換到linux,用該用戶試試:
[root@localhost ]# mysql -u myuser-p
Enter password:
ERROR 1045 (28000): Access denied for user 'myuser'@'localhost' (using password:
但發(fā)現(xiàn)mysql workbench用該用戶訪問一切正常,因?yàn)槲沂怯胢ysql workbench創(chuàng)建的用戶,但到linux又登錄不了。
下面是試錯(cuò)的過程,但既然后面可以登錄了
(1)、修改密碼
[root@localhost ]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 614
Server version: 5.6.25 MySQL Community Server (GPL)
Copyright (c) 2000, 2015, 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> use mysql ?。袚Q數(shù)據(jù)庫(kù)
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> update user set password=password("123456") where user="root"; --更改root用戶密碼
Query OK, 3 rows affected (0.00 sec)
Rows matched: 5 Changed: 3 Warnings: 0
mysql> update user set password=password("123456") where user="myuser"; --更改myuser用戶密碼
Query OK, 4 rows affected (0.00 sec)
Rows matched: 5 Changed: 4 Warnings: 0
發(fā)現(xiàn)用這個(gè)命令修改密碼提示:ERROR 1146 (42S02): Table 'mydb.user' doesn't exist
參考:http://www.cnblogs.com/fly1988happy/archive/2011/12/15/2288554.html
update mysql.user set password=password('新密碼') where User="test" and Host="localhost"; -- 最后這樣更改才ok
mysql> exit --退出
(2)、再登錄,還是報(bào)錯(cuò)
[root@localhost logs]# mysql -u myuser-p
Enter password:
ERROR 1045 (28000): Access denied for user 'myuser'@'localhost' (using password:
(3)、再試錯(cuò)。
[root@localhost ]# /etc/init.d/mysql stop ?。V狗?wù)
Shutting down MySQL..... SUCCESS!
[root@localhost ]# /usr/bin/mysqld_safe --skip-grant-tables
-bash: /usr/bin/mysqld_safe: No such file or directory
[root@localhost ]# mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
[1] 1791
[root@localhost ]# 150613 11:20:01 mysqld_safe Logging to '/usr/local/mysql/ data/localhost.localdomain.err'.
150613 11:20:02 mysqld_safe Starting mysqld daemon with databases from /usr/loca l/mysql/data
^C --按ctrl + c 退出
[root@localhost ]# mysqld_safe --user=mysql --skip-grant-tables --skip-networking
150613 11:21:27 mysqld_safe Logging to '/usr/local/mysql/data/localhost.localdom ain.err'.
150613 11:21:27 mysqld_safe A mysqld process already exists
[root@localhost ]# /etc/rc.d/init.d/mysql restart --啟動(dòng)服務(wù)
[root@localhost ]# mysql -u myuser-p -- 再登錄,既然可以了,然后應(yīng)用也可以登錄
(4)、總結(jié)
先登錄 mysql
# mysql -u root -p
mysql> use mysql --切換
mysql> select host,user,Password from user; --查看用戶和密碼情況,其實(shí)從這里就可以發(fā)現(xiàn)問題,不行就往下
# /etc/init.d/mysql stop
# mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
# mysql -u root -p
mysql> UPDATE user SET Password=PASSWORD('newpassword') where USER='root';
mysql> FLUSH PRIVILEGES;
mysql> quit
# /etc/init.d/mysqld restart
# mysql -u myuser -p
參考:http://www.bxl.me/zh-cn/2567.html
http://blog.csdn.net/lyflower/article/details/6137021
http://blog.csdn.net/vurtne_ye/article/details/26514499
聯(lián)系客服