相关软件环境
CentOS 6.5
Server version: 5.5.39-log MySQL Community Server (GPL) 软件包的名字mysql-5.5.39-linux2.6-x86_64.tar.gz 大小180M
1. 安装软件补丁
2. 上传mysql二进制软件包,并且解压
3. 配置MySQL用户赋给权限
4. 初始化Mysql数据库
5. 修改mysql目录属主为root
6. 生成MYSQL启动服务
7. 生成mysql主配置文件my.cnf
8. 配置my.cnf文件
9. 启动mysql
10.配置环境变量
11.访问MYSQL及其它相关配置
=============================================================
1.安装软件补
#这时一定要确定internet可以连接,才能使用下面命令
[root@mdb03 /]# yum install gcc gcc-c++ kernel-devel
[root@mdb03 /]# yum install -y ncurses-devel
[root@mdb03 /]# yum install -y libaio.so.1
[root@mdb03 /]# yum install -y libaio
[root@mdb03 /]# yum install -y ncurses-devel
[root@mdb03 /]# yum install -y make
[root@mdb03 /]# yum install -y cmake
[root@mdb03 /]# yum install -y bison
[root@mdb03 /]# yum groupinstall "Development Libraries" -y
=============================================================
2.上传mysql二进制软件包,并且解压
#上传二进mysql软件mysql-5.5.39-linux2.6-x86_64.tar.gz 大小180M
#解压软件
[root@mdb03 ~]# cd /usr/local
[root@mdb03 app]# tar zxvf mysql-5.5.39-linux2.6-x86_64.tar.gz
#软件目录改名
[root@mdb03 app]# mv mysql-5.5.39-linux2.6-x86_64 mysql
[root@mdb03 local]# ls
bin etc games include lib lib64 libexec mysql mysql-5.5.39-linux2.6-x86_64.tar.gz sbin share src
=============================================================
3.配置MySQL用户赋给权限
[root@mdb03 /]# groupadd -r mysql
[root@mdb03 /]# useradd -g mysql -r -s /sbin/nologin mysql
[root@mdb03 /]# mkdir -p /mydata/data
[root@mdb03 /]# ln -s mysql mysql
[root@mdb03 /]# chown -R mysql:mysql /usr/local/mysql/*
[root@mdb03 /]# chown -R mysql:mysql /mydata/data
[root@mdb03 local]# cd mysql
#查看当前所在路径
[root@mdb03 mysql]# pwd
/usr/local/mysql
[root@mdb03 mysql]# ls
bin COPYING data docs include INSTALL-BINARY lib man mysql-test README scripts share sql-bench support-files
[root@mdb03 mysql]# ls -lh
total 200K
drwxr-xr-x. 2 mysql mysql 4.0K Oct 30 14:55 bin
-rw-r--r--. 1 mysql mysql 18K Jul 19 14:25 COPYING
drwxr-xr-x. 3 mysql mysql 4.0K Oct 30 14:55 data
drwxr-xr-x. 2 mysql mysql 4.0K Oct 30 14:55 docs
drwxr-xr-x. 3 mysql mysql 4.0K Oct 30 14:55 include
-rw-r--r--. 1 mysql mysql 131K Jul 19 14:25 INSTALL-BINARY
drwxr-xr-x. 3 mysql mysql 4.0K Oct 30 14:55 lib
drwxr-xr-x. 4 mysql mysql 4.0K Oct 30 14:55 man
drwxr-xr-x. 10 mysql mysql 4.0K Oct 30 14:55 mysql-test
-rw-r--r--. 1 mysql mysql 2.5K Jul 19 14:25 README
drwxr-xr-x. 2 mysql mysql 4.0K Oct 30 14:55 scripts
drwxr-xr-x. 27 mysql mysql 4.0K Oct 30 14:55 share
drwxr-xr-x. 4 mysql mysql 4.0K Oct 30 14:55 sql-bench
drwxr-xr-x. 2 mysql mysql 4.0K Oct 30 14:55 support-files
[root@mdb03 mysql]# pwd
/usr/local/mysql
[root@mdb03 local]# cd mysql
[root@mdb03 mysql]# ls
bin COPYING data docs include INSTALL-BINARY lib man mysql-test README scripts share sql-bench support-files
[root@mdb03 mysql]# ls scripts/
mysql_install_db
[root@mdb03 ~]# chmod 775 /mydata/data
=================================================================================
4.初始化Mysql数据库
[root@mdb03 mysql]# scripts/mysql_install_db --user=mysql --datadir=/mydata/data/
Installing MySQL system tables...
OK
Filling help tables...
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:
./bin/mysqladmin -u root password 'new-password'
./bin/mysqladmin -u root -h mdb03 password 'new-password'
Alternatively you can run:
./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 . ; ./bin/mysqld_safe &
You can test the MySQL daemon with mysql-test-run.pl
cd ./mysql-test ; perl mysql-test-run.pl
Please report any problems at http://bugs.mysql.com/
=================================================================================
5.修改mysql目录属主为root
[root@mdb03 mysql]# chown -R root .
或是用
[root@mdb03 mysql]# chown -R root /usr/local/mysql/*
[root@mdb03 mysql]# ls -lh
total 200K
drwxr-xr-x. 2 root mysql 4.0K Oct 30 14:55 bin
-rw-r--r--. 1 root mysql 18K Jul 19 14:25 COPYING
drwxr-xr-x. 3 root mysql 4.0K Oct 30 14:55 data
drwxr-xr-x. 2 root mysql 4.0K Oct 30 14:55 docs
drwxr-xr-x. 3 root mysql 4.0K Oct 30 14:55 include
-rw-r--r--. 1 root mysql 131K Jul 19 14:25 INSTALL-BINARY
drwxr-xr-x. 3 root mysql 4.0K Oct 30 14:55 lib
drwxr-xr-x. 4 root mysql 4.0K Oct 30 14:55 man
drwxr-xr-x. 10 root mysql 4.0K Oct 30 14:55 mysql-test
-rw-r--r--. 1 root mysql 2.5K Jul 19 14:25 README
drwxr-xr-x. 2 root mysql 4.0K Oct 30 14:55 scripts
drwxr-xr-x. 27 root mysql 4.0K Oct 30 14:55 share
drwxr-xr-x. 4 root mysql 4.0K Oct 30 14:55 sql-bench
drwxr-xr-x. 2 root mysql 4.0K Oct 30 14:55 support-files
=================================================================================
6.生成MYSQL启动服务
# cd /usr/local/mysql
[root@mdb03 mysql]# cd /usr/local/mysql/support-files
[root@mdb03 support-files]# cp mysql.server /etc/rc.d/init.d/mysqld
[root@mdb03 support-files]# ls /etc/rc.d/init.d/mysqld
/etc/rc.d/init.d/mysqld
[root@mdb03 support-files]# chkconfig --add mysqld
[root@mdb03 support-files]# chkconfig --list mysqld
mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off
================================================================================
7.生成mysql主配置文件my.cnf
f
#cd /opt/app/mysql/support-files
[root@mdb03 support-files]# cp my-large.cnf /etc/my.cnf
#mysql查询my.cnf文件位置的过程
查询/etc/my.cnf-->/etc/mysql/my.cnf-->$BASEDIR/my.cnf-->$BASEDIR/my.cnf-->~/.my.cnf
#如果以上位置都没有找到my.cnf哪么它将自动以默认方式启动mysql
================================================================================
8.配置my.cnf文件
[root@mdb03 support-files]# vi /etc/my.cnf
[mysqld]
port = 3306
socket = /tmp/mysql.sock
skip-external-locking
key_buffer_size = 256M
max_allowed_packet = 1M
table_open_cache = 256
sort_buffer_size = 1M
read_buffer_size = 1M
read_rnd_buffer_size = 4M
myisam_sort_buffer_size = 64M
thread_cache_size = 8
query_cache_size= 16M
# Try number of CPU's*2 for thread_concurrency
thread_concurrency = 8
datadir = /mydata/data #添加数据库存储路径,这个配置是一定需要
:wq
================================================================================
9.启动mysql
[root@mdb03 support-files]# service mysqld start
Starting MySQL... SUCCESS!
#这时候会自动生成socket = /tmp/mysql.sock在相关位置
[root@mdb03 support-files]# netstat -tnlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1774/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 913/master
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 2252/mysqld
tcp 0 0 :::22 :::* LISTEN 1774/sshd
tcp 0 0 ::1:25 :::* LISTEN 913/master
================================================================================
10.配置环境变量
[root@mdb03 support-files]# mysql
-bash: mysql: command not found
#没有生成环境变量,生成环境变量
vi /etc/profile.d/mysql.sh
export PATH=$PATH:/usr/local/mysql/bin
:wq
[root@mdb03 support-files]# sh /etc/profile.d/mysql.sh
#查看环境变量是否加载成功,注意这里需要重新开终端才能看到
[root@mdb03 etc]# echo $PATH
/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/mysql/bin:/root/bin
================================================================================
11.访问MYSQL及其它相关配置
#关闭终端重新访问,输入命令,直接访问mysql
[root@mdb03 ~]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.39-log MySQL Community Server (GPL)
Copyright (c) 2000, 2014, 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>
================================================================================
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.01 sec)
mysql> show engines;
+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
| Engine | Support | Comment | Transactions | XA | Savepoints |
+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
| PERFORMANCE_SCHEMA | YES | Performance Schema | NO | NO | NO |
| MRG_MYISAM | YES | Collection of identical MyISAM tables | NO | NO | NO |
| CSV | YES | CSV storage engine | NO | NO | NO |
| BLACKHOLE | YES | /dev/null storage engine (anything you write to it disappears) | NO | NO | NO |
| MEMORY | YES | Hash based, stored in memory, useful for temporary tables | NO | NO | NO |
| InnoDB | DEFAULT | Supports transactions, row-level locking, and foreign keys | YES | YES | YES |
| ARCHIVE | YES | Archive storage engine | NO | NO | NO |
| MyISAM | YES | MyISAM storage engine | NO | NO | NO |
| FEDERATED | NO | Federated MySQL storage engine | NULL | NULL | NULL |
+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
9 rows in set (0.00 sec)
================================================================================
#管理员用户加密码和删除匿名用户及其它无用用户
mysql> drop user ''@localhost;
Query OK, 0 rows affected (0.01 sec)
mysql> use mysql;
Database changed
mysql> select user,host,password from user;
+------+-----------+----------+
| user | host | password |
+------+-----------+----------+
| root | localhost | |
| root | mdb03 | |
| root | 127.0.0.1 | |
| root | ::1 | |
| | mdb03 | |
+------+-----------+----------+
5 rows in set (0.00 sec)
mysql> drop user ''@'mdb03';
Query OK, 0 rows affected (0.00 sec)
mysql> drop user 'root'@'::1'; #删除ipv6监听用户
Query OK, 0 rows affected (0.00 sec)
mysql> update user set password=password('oracle') where user='root';
Query OK, 3 rows affected (0.00 sec)
Rows matched: 3 Changed: 3 Warnings: 0
mysql> select user,host,password from user;
+------+-----------+-------------------------------------------+
| user | host | password |
+------+-----------+-------------------------------------------+
| root | localhost | *2447D497B9A6A15F2776055CB2D1E9F86758182F |
| root | mdb03 | *2447D497B9A6A15F2776055CB2D1E9F86758182F |
| root | 127.0.0.1 | *2447D497B9A6A15F2776055CB2D1E9F86758182F |
+------+-----------+-------------------------------------------+
3 rows in set (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> \q
Bye
[root@mdb03 etc]# mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
[root@mdb03 etc]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.5.39-log MySQL Community Server (GPL)
Copyright (c) 2000, 2014, 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>
#MYSQL的启动与关闭
关闭
[root@mdb03 lib]# service mysqld stop
Shutting down MySQL... SUCCESS!
启动
[root@mdb03 lib]# service mysqld start
Starting MySQL.. SUCCESS!
================================================================================
#输出库文件
vi /etc/ld.so.conf.d/mysql.conf
/usr/local/mysql/lib
:wq
================================================================================
#输出库文件
[root@mdb03 lib]# ldconfig -v
/usr/local/mysql/lib:
libtcmalloc_minimal.so.0 -> libtcmalloc_minimal.so (changed)
libmysqlclient.so.18 -> libmysqlclient_r.so.18.0.0
/usr/lib64/mysql:
libmysqlclient_r.so.16 -> libmysqlclient_r.so.16.0.0
libmysqlclient.so.16 -> libmysqlclient.so.16.0.0
/lib:
libaio.so.1 -> libaio.so.1.0.1
libaio.so.1.0.0 -> libaio.so.1.0.0
/lib64:
libnss_nis.so.2 -> libnss_nis-2.12.so
libsemanage.so.1 -> libsemanage.so.1
libreadline.so.6 -> libreadline.so.6.0
libacl.so.1 -> libacl.so.1.1.0
libaudit.so.1 -> libaudit.so.1.0.0
等等信息...................
==================================================================================
#输出头文件
[root@mdb03 lib]# ln -sv /usr/local/mysql/include /usr/include/mysql
`/usr/include/mysql' -> `/usr/local/mysql/include'