0. 到官网下载好,想要安装的rpm包,本人使用的是
MySQL-server-5.5.50-1.linux2.6.x86_64.rpm 和 MySQL-client-5.5.50-1.linux2.6.x86_64.rpm
下载完之后可以放在/usr/local/mysql 里(个人习惯,只要找的到就行)
1.查看系统是否有安装过的rpm包
rpm -qa | grep -i mysql
2.查看CentOS自带mysql是否已安装。
yum list installed | grep mysql
3.卸载所有安装
yum -y remove mysql-libs*(删除mysql-libs开头的所以安装文件,如有其他文件可直接更换文件名进行删除)
4.删除其他文件(如果没有不用操作)
rm -rf /var/lib/mysql*
rm -rf /usr/share/mysql*
5.删除其他文件
卸载后 /etc/my.cnf 会重命名为 my.cnf.rpmsave,/var/log/mysqld.log 会重命名为 /var/log/mysqld.log.rpmsave,删除两个文件
6.安装服务端
rpm -ivh MySQL-server-5.5.50-1.linux2.6.x86_64.rpm (执行此命令要到MySQL-server-5.5.50-1.linux2.6.x86_64.rpm所在目录)
以下是成功日志内容:
Preparing... ########################################### [100%]
1:MySQL-server ########################################### [100%]
warning: user mysql does not exist - using root
warning: group mysql does not exist - using root
2014-08-10 22:43:44 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2014-08-10 22:43:44 23012 [Note] InnoDB: Using atomics to ref count buffer pool pages
2014-08-10 22:43:44 23012 [Note] InnoDB: The InnoDB memory heap is disabled
2014-08-10 22:43:44 23012 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2014-08-10 22:43:44 23012 [Note] InnoDB: Memory barrier is not used
2014-08-10 22:43:44 23012 [Note] InnoDB: Compressed tables use zlib 1.2.3
2014-08-10 22:43:44 23012 [Note] InnoDB: Using Linux native AIO
2014-08-10 22:43:44 23012 [Note] InnoDB: Not using CPU crc32 instructions
2014-08-10 22:43:44 23012 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2014-08-10 22:43:44 23012 [Note] InnoDB: Completed initialization of buffer pool
2014-08-10 22:43:45 23012 [Note] InnoDB: The first specified data file ./ibdata1 did not exist: a new database to be created!
2014-08-10 22:43:45 23012 [Note] InnoDB: Setting file ./ibdata1 size to 12 MB
2014-08-10 22:43:45 23012 [Note] InnoDB: Database physically writes the file full: wait...
2014-08-10 22:43:45 23012 [Note] InnoDB: Setting log file ./ib_logfile101 size to 48 MB
2014-08-10 22:43:46 23012 [Note] InnoDB: Setting log file ./ib_logfile1 size to 48 MB
2014-08-10 22:43:46 23012 [Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0
2014-08-10 22:43:46 23012 [Warning] InnoDB: New log files created, LSN=45781
2014-08-10 22:43:46 23012 [Note] InnoDB: Doublewrite buffer not found: creating new
2014-08-10 22:43:46 23012 [Note] InnoDB: Doublewrite buffer created
2014-08-10 22:43:46 23012 [Note] InnoDB: 128 rollback segment(s) are active.
2014-08-10 22:43:46 23012 [Warning] InnoDB: Creating foreign key constraint system tables.
2014-08-10 22:43:47 23012 [Note] InnoDB: Foreign key constraint system tables created
2014-08-10 22:43:47 23012 [Note] InnoDB: Creating tablespace and datafile system tables.
2014-08-10 22:43:47 23012 [Note] InnoDB: Tablespace and datafile system tables created.
2014-08-10 22:43:47 23012 [Note] InnoDB: Waiting for purge to start
2014-08-10 22:43:47 23012 [Note] InnoDB: 5.6.22 started; log sequence number 0
A random root password has been set. You will find it in '/root/.mysql_secret'.
2014-08-10 22:43:48 23012 [Note] Binlog end
2014-08-10 22:43:48 23012 [Note] InnoDB: FTS optimize thread exiting.
2014-08-10 22:43:48 23012 [Note] InnoDB: Starting shutdown...
2014-08-10 22:43:50 23012 [Note] InnoDB: Shutdown completed; log sequence number 1625977
2014-08-10 22:43:50 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2014-08-10 22:43:50 23039 [Note] InnoDB: Using atomics to ref count buffer pool pages
2014-08-10 22:43:50 23039 [Note] InnoDB: The InnoDB memory heap is disabled
2014-08-10 22:43:50 23039 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2014-08-10 22:43:50 23039 [Note] InnoDB: Memory barrier is not used
2014-08-10 22:43:50 23039 [Note] InnoDB: Compressed tables use zlib 1.2.3
2014-08-10 22:43:50 23039 [Note] InnoDB: Using Linux native AIO
2014-08-10 22:43:50 23039 [Note] InnoDB: Not using CPU crc32 instructions
2014-08-10 22:43:50 23039 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2014-08-10 22:43:50 23039 [Note] InnoDB: Completed initialization of buffer pool
2014-08-10 22:43:50 23039 [Note] InnoDB: Highest supported file format is Barracuda.
2014-08-10 22:43:50 23039 [Note] InnoDB: 128 rollback segment(s) are active.
2014-08-10 22:43:50 23039 [Note] InnoDB: Waiting for purge to start
2014-08-10 22:43:50 23039 [Note] InnoDB: 5.6.22 started; log sequence number 1625977
2014-08-10 22:43:50 23039 [Note] Binlog end
2014-08-10 22:43:50 23039 [Note] InnoDB: FTS optimize thread exiting.
2014-08-10 22:43:50 23039 [Note] InnoDB: Starting shutdown...
2014-08-10 22:43:52 23039 [Note] InnoDB: Shutdown completed; log sequence number 1625987
A RANDOM PASSWORD HAS BEEN SET FOR THE MySQL root USER !
You will find that password in '/root/.mysql_secret'.
You must change that password on your first connect,
no other statement but 'SET PASSWORD' will be accepted.
See the manual for the semantics of the 'password expired' flag.
Also, the account for the anonymous user has been removed.
In addition, you can run:
/usr/bin/mysql_secure_installation
which will also give you the option of removing the test database.
This is strongly recommended for production servers.
See the manual for more instructions.
Please report any problems at http://bugs.mysql.com/
The latest information about MySQL is available on the web at
http://www.mysql.com
Support MySQL by buying support/licenses at http://shop.mysql.com
New default config file was created as /usr/my.cnf and
will be used by default by the server when you start it.
You may edit this file to change server settings
7.启动服务
service mysql start
以下是成功日志:
Starting MySQL.......... SUCCESS!
8.安装客户端
rpm -ivh MySQL-client-5.5.50-1.linux2.6.x86_64.rpm(执行此命令要在MySQL-client-5.5.50-1.linux2.6.x86_64.rpm所在目录)
以下是成功日志
Preparing... ########################################### [100%]
1:MySQL-client ^C########################################### [100%] 安装完成
9.文件配置
找到my.cnf配置文件
如果"/etc/"目录下没有my.cnf配置文件,请到 "/usr/share/mysql/" 下找到 my-default.cnf 文件,拷贝其中一个合适的配置文件到 "/etc/" 并改名为 "my.cnf" 中。命令如下:
cp /usr/share/mysql/my-medium.cnf /etc/my.cnf
10.修改上一步拷贝的my.cnf文件(配置/etc/my.cnf文件,修改数据存放路径、mysql.sock路径以及默认编码utf-8.)
[client]
password = 123456
port = 3306
default-character-set=utf8
[mysqld]
port = 3306
character_set_server=utf8
character_set_client=utf8
collation-server=utf8_general_ci
#(注意linux下mysql安装完后是默认:表名区分大小写,列名不区分大小写; 0:区分大小写,1:不区分大小写)
lower_case_table_names=1
#(设置最大连接数,默认为 151,MySQL服务器允许的最大连接数16384; )
max_connections=1000
[mysql]
default-character-set = utf8
11.设置Mysql开机启动
chkconfig mysqld on
12.开启3306端口并保存
1./sbin/iptables -I INPUT -p tcp --dport 3306 -j ACCEPT
2./etc/rc.d/init.d/iptables save
13.连接mysql数据库
mysql -uroot -p
此时会提示你输入密码,直接enter 键;
14.修改mysql密码
1.update user set password=password('密码') where user='root';
2.flush privileges;
15.设置Mysql远程访问
grant all privileges on *.* to 'root'@'%' identified by '123456' with grant option;
其中123456是你设置的远程连接密码。
16.. MySQL的默认rpm安装位置
1
/var/lib/mysql/ #数据库目录
2
/usr/share/mysql #配置文件目录
3
/usr/bin #相关命令目录
4
/etc/init.d/mysql #启动脚本
---------------------
作者:Y_JY