MySQL之安装(一)

1、解压安装cmake 
yum install gcc*
[root@CentOs ~]# cd  cmake-2.8.8
[root@CentOs cmake-2.8.8]# ./configure 
CMake has bootstrapped.  Now run gmake.
[root@CentOs cmake-2.8.8]# gmake
[root@CentOs cmake-2.8.8]# gmake install 
#安装依赖包
yum install ncurses-devel -y 
创建mysql用户和用户组
groupadd mysql 
useradd mysql -s /sbin/nologin -M -g mysql 
[root@CentOs ~]# cd  mysql-5.5.32
cmake . -DCMAKE_INSTALL_PREFIX=/application/mysql-5.5.32 -DMYSQL_DATADIR=/application/mysql-5.5.32/data -DMYSQL_UNIX_ADDR=/application/mysql-5.5.32/tmp/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=gbk,gb2312,utf8,ascill -DENABLED_LOCAL_INFILE=ON
[root@CentOs mysql-5.5.32]# make 
[root@CentOs mysql-5.5.32]# make install
[root@CentOs ~]# ln -s /application/mysql-5.5.32/ /application/mysql
配置文件的copy:
You have mail in /var/spool/mail/root
[root@CentOs ~]# cp mysql-5.5.32/support-files/my-small.cnf /etc/my.cnf
cp:是否覆盖"/etc/my.cnf"? y
[root@CentOs ~]# 
配置环境变量,初始化mysql :
[root@CentOs ~]# echo 'export PATH=/application/mysql/bin:$PATH' >>/etc/profile
[root@CentOs ~]# tail -l /etc/profile 
            . "$i"
        else
            . "$i" >/dev/null 2>&1
        fi
    fi
done
 
unset i
unset -f pathmunge
export PATH=/application/mysql/bin:$PATH
[root@CentOs ~]# source  /etc/profile 
[root@CentOs ~]# echo $PATH 
/application/mysql/bin:/usr/lib/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
[root@CentOs ~]# 
#初始化数据文件:
[root@CentOs ~]# mkdir -p /application/mysql/data
#建立mysql数据文件目录:
[root@CentOs ~]# chown -R mysql.mysql /application/mysql/
#授权mysql用户访问mysql的安装目录:
[root@CentOs ~]# chmod -R 1777 /tmp
初始化见如下:
[root@CentOs ~]# cd  /application/mysql/scripts/
[root@CentOs scripts]# ./mysql_install_db --basedir=/application/mysql/ --datadir=/application/mysql/data/ --user=mysql
出现如的信息,表示mysql初始化成功,见信息:
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:
 
/application/mysql//bin/mysqladmin -u root password 'new-password'
/application/mysql//bin/mysqladmin -u root -h CentOs password 'new-password'
 
Alternatively you can run:
/application/mysql//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 /application/mysql/ ; /application/mysql//bin/mysqld_safe &
 
You can test the MySQL daemon with mysql-test-run.pl
cd /application/mysql//mysql-test ; perl mysql-test-run.pl
 
Please report any problems with the /application/mysql//scripts/mysqlbug script!
 
#copymysql的服务
[root@CentOs mysql-5.5.32]# cp support-files/mysql.server /etc/init.d/mysqld 
#给mysqld服务加权限
[root@CentOs mysql-5.5.32]# chmod +x /etc/init.d/mysqld
#启动mysql的服务
[root@CentOs mysql-5.5.32]# /etc/init.d/mysqld  start 
Starting MySQL...                                          [确定]
[root@CentOs mysql-5.5.32]# lsof -i:3306
COMMAND   PID  USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
mysqld  15631 mysql   10u  IPv4 117855      0t0  TCP *:mysql (LISTEN)
或者使用如下方式查看端口:
[root@CentOs mysql-5.5.32]# netstat -lntup | grep 3306 
tcp        0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN      15951/mysqld        
[root@CentOs mysql-5.5.32]# 
进入mysql后操作如下的命令:
mysql> select user,host from mysql.user;
+------+-----------+
| user | host      |
+------+-----------+
| root | 127.0.0.1 |
| root | ::1       |
|      | CentOs    |
| root | CentOs    |
|      | localhost |
| root | localhost |
+------+-----------+
6 rows in set (0.01 sec)
 
mysql> delete from mysql.user where user='' and host='CentOs';
Query OK, 1 row affected (0.01 sec)
 
mysql> select user,host from mysql.user;
+------+-----------+
| user | host      |
+------+-----------+
| root | 127.0.0.1 |
| root | ::1       |
| root | CentOs    |
|      | localhost |
| root | localhost |
+------+-----------+
5 rows in set (0.00 sec)
最后查询显示如下的表示是OK的,见如下的内容:
mysql> select user,host from mysql.user;
+------+-----------+
| user | host      |
+------+-----------+
| root | 127.0.0.1 |
| root | ::1       |
| root | localhost |
+------+-----------+
3 rows in set (0.00 sec)
 
设置mysql的命令:
[root@CentOs mysql-5.5.32]# mysqladmin  -u root password 'server'
#设置mysql自动启动
[root@CentOs ~]# chkconfig mysqld on 
[root@CentOs ~]# chkconfig --list mysqld 
mysqld          0:关闭  1:关闭  2:启用  3:启用  4:启用  5:启用  6:关闭
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
posted @ 2017-08-16 21:22  无涯(WuYa)  阅读(373)  评论(0编辑  收藏  举报