在Linux上安装MySQL-5.5.20-1.linux2.6.x86_64.tar教程
来源:互联网 发布:找图片的网站 知乎 编辑:程序博客网 时间:2024/05/07 06:07
网盘资源:http://pan.baidu.com/s/1miPFiha
CREATE USER 'username'@'%' IDENTIFIED BY 'password';
GRANT ALL ON *.* TO 'username'@'%';
<span style="white-space:pre"></span>mysql> use mysql mysql> delete from user where user=''; mysql> flush privileges;意思是删除匿名用户。
一、从官网下载MySQL Community Server
http://www.mysql.com/downloads/
选择相应的系统,通常linux选择Linux-Generic
下载即可
二、创建用户
首先创建mysql用户,组mysql,根目录/home/mysql
命令 groupadd mysql
useradd -g mysql -d /home/mysql mysql
三、将安装包ftp传至/home/mysql/install下解压
(最好建一个install目录,因为会解压出来很多包)
MySQL-5.5.20-1.linux2.6.x86_64.tar传至/home/mysql/install
[mysql@hadoop2 ~]$pwd
/home/mysql/install
[mysql@hadoop2 ~]$ ls -l
total 183164
-rw-r--r-- 1 mysql mysql 187371520 Feb 10 10:32 MySQL-5.5.20-1.linux2.6.x86_64.tar
[mysql@hadoop2 ~]$ tar xvf MySQL-5.5.20-1.linux2.6.x86_64.tar
MySQL-client-5.5.20-1.linux2.6.x86_64.rpm
MySQL-devel-5.5.20-1.linux2.6.x86_64.rpm
MySQL-embedded-5.5.20-1.linux2.6.x86_64.rpm
MySQL-server-5.5.20-1.linux2.6.x86_64.rpm
MySQL-shared-5.5.20-1.linux2.6.x86_64.rpm
MySQL-test-5.5.20-1.linux2.6.x86_64.rpm
四、安装
1、先查看原主机上又没有mysql(root用户操作)
[root@hadoop2 install]$ rpm -qa|grep mysql
mysql-5.0.77-4.el5_5.4
如果有继续安装,会如下安装失败:
[root@hadoop2 install]$ rpm -ivh MySQL-server-5.5.20-1.linux2.6.x86_64.rpm
error: Failed dependencies:
MySQL conflicts with mysql-5.0.77-4.el5_5.4.x86_64
所以要先卸载或升级,但是我升级和卸载都报了一个依赖的错,因为有个dovecot依赖如下,最后加了个--nodeps参数解决,
[root@hadoop2 install]$ rpm -Uvh MySQL-server-5.5.20-1.linux2.6.x86_64.rpm
error: Failed dependencies:
libmysqlclient.so.15()(64bit) is needed by (installed) dovecot-1.0.7-7.el5.x86_64
libmysqlclient.so.15(libmysqlclient_15)(64bit) is needed by (installed) dovecot-1.0.7-7.el5.x86_64
[root@hadoop2 install]$ rpm -e mysql-5.0.77-4.el5_5.4
error: Failed dependencies:
libmysqlclient.so.15()(64bit) is needed by (installed) dovecot-1.0.7-7.el5.x86_64
libmysqlclient.so.15(libmysqlclient_15)(64bit) is needed by (installed) dovecot-1.0.7-7.el5.x86_64
[root@hadoop2 install]rpm -e mysql-5.0.77-4.el5_5.4 --nodeps
[root@hadoop2 home]# rpm -qa|grep mysql
[root@hadoop2 home]#
2、安装server和client
[root@hadoop2 install]# rpm -ivh MySQL-server-5.5.20-1.linux2.6.x86_64.rpm
Preparing... ########################################### [100%]
1:MySQL-server ########################################### [100%]
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 hadoop2 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.
Please report any problems with the /usr/bin/mysqlbug script!
Notes regarding SELinux on this platform:
=========================================
The default policy might cause server startup to fail because it is
not allowed to access critical files. In this case, please update
your installation.
The default policy might also cause inavailability of SSL related
features because the server is not allowed to access /dev/random
and /dev/urandom. If this is a problem, please do the following:
1) install selinux-policy-targeted-sources from your OS vendor
2) add the following two lines to /etc/selinux/targeted/src/policy/domains/program/mysqld.te:
allow mysqld_t random_device_t:chr_file read;
allow mysqld_t urandom_device_t:chr_file read;
3) cd to /etc/selinux/targeted/src/policy and issue the following command:
make load
[root@hadoop2 install]rpm -ivh MySQL-client-5.5.20-1.linux2.6.x86_64.rpm
Preparing... ########################################### [100%]
1:MySQL-client ########################################### [100%]
[root@hadoop2 install]#chown -R mysql:mysql /usr/share/mysql
3、安装完启动
[mysql@hadoop2 mysql]$pwd
/usr/share/mysql
[mysql@hadoop2 mysql]$ /usr/share/mysql/mysql.server start
Starting MySQL..[ OK ]
./mysql.server脚本是调用/usr/bin/mysqld_safe来启动mysql的
4、查看mysql是否启动,看进程+3306端口
[mysql@hadoop2 mysql]$ netstat -an|grep 3306
tcp 0 0 :::3306 :::* LISTEN
[mysql@hadoop2 mysql]$ ps -ef|grep mysqld_safe
mysql 4637 1 0 11:54 pts/0 00:00:00 /bin/sh /usr/bin/mysqld_safe --datadir=/var/lib/mysql --pid-file=/var/lib/mysql/hadoop2.pid
mysql 5001 4606 0 13:50 pts/0 00:00:00 grep mysqld_safe
5、设定root用户密码
[root@hadoop2 mysql]# mysqladmin -u root password 'udmu2015'
这是第一次设定,如果修改就是
mysqladmin -u root -p旧密码password新密码
6、尝试连接
[mysql@hadoop2 ~]$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.5.20 MySQL Community Server (GPL)
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>
7、修改可以远程登录
mysql>use mysql
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> select host,user, Password ,Select_priv from user;
mysql> grant all on *.* to root@'%' identified by'udmu2015';
Query OK, 0 rows affected (0.00 sec)
mysql> select host,user from user where user='root';
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
这样远程登录就可以成功了。√
如果不能客户端远程连接,要关闭防火墙。
[mysql@hadoop2 /]$ serviceiptables stop
8、修改字符集
查看原字符集:
mysql>use mysql
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> show variables like 'character_set%' ;
mysql> show variables like 'collation_%';
需要将/usr/share/mysql/my-huge.cnf
my-innodb-heavy-4G.cnf
my-large.cnf
my-medium.cnf
my-small.cnf
任意一个(根据数据库的需求,本例用large)copy至/etc下,修改为my.cnf
[root@hadoop2] cp /usr/share/mysql/my-large.cnf /etc/my.cnf
[root@hadoop2] vi /etc/my.cnf
在[client]下添加default-character-set=utf8
在[mysqld]下添加character_set_server=utf8
在[mysql] 下添加default-character-set=utf8
[mysql @hadoop2] /usr/share/mysql/mysql.server restart
进行查看
9、修改SQL不区分大小写
在/etc/my.cnf 中的[mysqld]后添加lower_case_table_names=1,重启MYSQL服务
10、支持procedure或者function编译及执行
在mysql中编译或者执行procedure或者function时,可能会报如下错误
This functionhas none of DETERMINISTIC, NO SQL, or READS SQL DATA in its declaration andbinary logging is enabled (you *might* want to use the less safelog_bin_trust_function_creators variable)
两种方法
(1) 在/etc/my.cnf 中的[mysqld]后添加添加log_bin_trust_function_creators = 1,重启MYSQL服务
(2) 在控制台执行SQL> set global log_bin_trust_function_creators = 1;
不过重启后会失效
五、启动停止
1、启动
[mysql@hadoop2 mysql]$pwd
/usr/share/mysql
[mysql@hadoop2 ~]$ /usr/share/mysql/mysql.server start
Starting MySQL..[ OK ]
2、停止
[mysql@hadoop2 ~]$ /usr/bin/mysqladmin –u root –p shutdown
Enter password:
或者
[mysql@hadoop2 ~]$ /usr/share/mysql/mysql.server stop
3、重启
[mysql@hadoop2 ~]$ /usr/share/mysql/mysql.server restart
4、通过chkconfig设置开机自动启动
[root@hadoop2 mysql]# chkconfig mysql on
[root@hadoop2 mysql]# chkconfig --list mysql
mysql 0:off 1:off 2:on 3:on 4:on 5:on 6:off
六、基本使用
mysql> show databases; //查看数据库
mysql> use test //选择数据库
Database changed
mysql> show tables; //查看表
Empty set (0.00 sec)
mysql> create table gl(id int(3) auto_increment not null primary key, name char(10) not null);
//创建表
Query OK, 0 rows affected (0.01 sec)
mysql> select * from gl;
Empty set (0.00 sec)
mysql> show tables; //再次查看表
mysql> insert into gl values("",'Guolei'); //插入数据
Query OK, 1 row affected, 1 warning (0.00 sec)
mysql> select * from gl; //查询数据
mysql> exit
Bye
七、备份数据库
使用mysqldump命令备份
[mysql@hadoop2 ~]$ /usr/bin/mysqldump -u root -p654321 --opt test>>test.bbb //单库备份
[mysql@hadoop2 ~]$ls –l
total 8
drwxrwxr-x 2 mysql mysql 4096 Feb 10 11:19 install
-rw-rw-r-- 1 mysql mysql 3690 Feb 10 14:54 test.bbb
[mysql@hadoop2 ~]$ mysqldump -u root –p654321 --opt --all-databases --lock-tables=false >dump.sql//全量备份
备份出来的test.bbb是个文本文件,可以使用more或者cat打开
使用mysqldump命令导入备份
[mysql@hadoop2 ~]$ mysql -u root -p test< test.bbb
Enter password:
备份注意:
mysqldump: Got error: 1066: Not uniquetable/alias: 'pmamap' when using LOCK TABLES
需要加上--lock-tables=false 参数
- 在Linux上安装MySQL-5.5.20-1.linux2.6.x86_64.tar教程
- 在Ubuntu上以tarball方式安装MySQL(mysql-5.5.14-linux2.6-x86_64.tar.gz)
- MySQL-5.5.49-1.linux2.6.x86_64.rpm-bundle.tar安装问题
- 如何在Linux上安装Mysql的二进制包(mysql-xxx-linux-xxx-x86_64.tar)
- ubuntu server 上部署 mysql-5.5.28-linux2.6-x86_64
- 安装 mysql-5.7.11-linux-glibc2.5-x86_64.tar.gz
- mysql-5.6.30-linux-glibc2.5-x86_64.tar.gz 安装
- mysql-5.6.30-linux-glibc2.5-x86_64.tar.gz 安装
- Linux安装MySQL-5.6.24-1.linux_glibc2.5.x86_64.rpm-bundle.tar
- Linux安装MySQL-5.6.24-1.linux_glibc2.5.x86_64.rpm-bundle.tar
- Linux安装MySQL-5.6.24-1.linux_glibc2.5.x86_64.rpm-bundle.tar
- linux6.5安装MySQL-5.5.53-1.el6.x86_64.rpm-bundle.tar
- 【Mysql】Linux下安装mysql-5.6.12-linux-glibc2.5-x86_64.tar.gz
- MySql(30)------linux下安装mysql-5.7.12-linux-glibc2.5-x86_64.tar.gz(centos)
- 虚拟机上Rathat6.3安装MySQL-5.6.16-1.rhel5.x86_64.rpm-bundle教程
- centos6.5安装mysql-advanced-5.7.9-linux-glibc2.5-x86_64.tar.gz为mysql service
- cenos安装mysql(mysql-5.6.21-linux-glibc2.5-x86_64.tar.gz)
- Linux CenterOS安装mysql-5.6.12-linux-glibc2.5-x86_64.tar.gz
- HDU 1078 FatMouse and Cheese (记忆化搜索)
- 自制摄像头测距装置
- 图片裁剪关于return-data
- 欢迎使用CSDN-markdown编辑器
- linux Oracle 启动
- 在Linux上安装MySQL-5.5.20-1.linux2.6.x86_64.tar教程
- 简单描述js闭包概念
- 记录一次很蠢的设计——没有考虑到重复元素的问题
- json-lib使用,JSONObject和JSONArray
- SDAU练习二总结
- 像素级动态模糊(Pixel Motion Blur)
- 准备写个博客记录下时光
- 编译预处理
- TCP/IP详解--拥塞控制 & 慢启动 快恢复 拥塞避免