一、环境
系统:CentOS 6.4x64最小化安装
IP:192.168.3.54
二、安装基础软件包
[root@httpd conf]# yum -y install make gcc-c++ cmake bison-devel ncurses-devel
三、安装mysql
1.创建用户
[root@httpd ~]# groupadd mysql [root@httpd ~]# useradd -g mysql mysql -s /sbin/nologin
2.解压软件包
[root@httpd ~]# tar xf mysql-5.5.37.tar.gz
3.编译配置参数
#创建用来存放Mysql数据的目录 [root@httpd ~]# mkdir -p /data/mysql/data [root@httpd ~]# cd mysql-5.5.37 [root@httpd mysql-5.5.37]# cmake > -DCMAKE_INSTALL_PREFIX=/usr/local/mysql-5.5.37 > -DMYSQL_DATADIR=/data/mysql/data > -DSYSCONFDIR=/etc > -DWITH_MYISAM_STORAGE_ENGINE=1 > -DWITH_INNOBASE_STORAGE_ENGINE=1 > -DWITH_MEMORY_STORAGE_ENGINE=1 > -DWITH_READLINE=1 > -DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock > -DMYSQL_TCP_PORT=3306 > -DENABLED_LOCAL_INFILE=1 > -DWITH_PARTITION_STORAGE_ENGINE=1 > -DEXTRA_CHARSETS=all > -DDEFAULT_CHARSET=utf8 > -DDEFAULT_COLLATION=utf8_general_ci [root@httpd mysql-5.5.37]# make && make install
4.数据目录初始化
[root@httpd mysql-5.5.37]# cd /usr/local/mysql-5.5.37/ [root@httpd mysql-5.5.37]# scripts/mysql_install_db --datadir=/data/mysql/data/ --user=mysql --basedir=/usr/local/mysql-5.5.37/ Installing MySQL system tables... OK Filling help tables... OK #到这里显示的有2个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: /usr/local/mysql-5.5.37//bin/mysqladmin -u root password ‘new-password‘ /usr/local/mysql-5.5.37//bin/mysqladmin -u root -h httpd password ‘new-password‘ Alternatively you can run: /usr/local/mysql-5.5.37//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 /usr/local/mysql-5.5.37/ ; /usr/local/mysql-5.5.37//bin/mysqld_safe & You can test the MySQL daemon with mysql-test-run.pl cd /usr/local/mysql-5.5.37//mysql-test ; perl mysql-test-run.pl Please report any problems at http://bugs.mysql.com/
5.复制mysql配置文件
[root@httpd mysql-5.5.37]# cp -rf support-files/my-large.cnf /etc/my.cnf
6.创建启动脚本
[root@httpd mysql-5.5.37]# cp support-files/mysql.server /etc/init.d/mysqld [root@httpd mysql-5.5.37]# chmod +x /etc/init.d/mysqld [root@httpd mysql-5.5.37]# /etc/init.d/mysqld start Starting MySQL.. SUCCESS! [root@httpd mysql-5.5.37]# netstat -anpt |grep mysql tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 21814/mysqld
7.连接到数据库
[root@httpd ~]# which mysql /usr/bin/which: no mysql in (/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin) #配置软连接 [root@httpd ~]# ln -s /usr/local/mysql-5.5.37/ /usr/local/mysql [root@httpd ~]# ln -s /usr/local/mysql-5.5.37/bin/* /usr/sbin/ [root@httpd ~]# which mysql /usr/sbin/mysql 连接到数据库 [root@httpd ~]# mysql Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1 Server version: 5.5.37-log Source distribution 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> #默认的情况下是没有密码的,设置root账号的密码,设置密码是ly36843 mysql> update user set password=password(‘lyao36843‘) where host="localhost" and user="root"; Query OK, 1 row affected (0.03 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> update user set password=password(‘lyao36843‘) where host="127.0.0.1" and user="root"; Query OK, 1 row affected (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> select user,host,password from mysql.user; +------+-----------+-------------------------------------------+ | user | host | password | +------+-----------+-------------------------------------------+ | root | localhost | *B181A5BCA7C882221F5B8F6F9657AE71FF67EDDB | | root | httpd | | | root | 127.0.0.1 | *B181A5BCA7C882221F5B8F6F9657AE71FF67EDDB | | root | ::1 | | | | localhost | | | | httpd | | +------+-----------+-------------------------------------------+ 6 rows in set (0.00 sec) #清除mysql用户表中不安全的用户 mysql> delete from mysql.user where password=‘‘; Query OK, 4 rows affected (0.03 sec) mysql> select user,host,password from mysql.user; +------+-----------+-------------------------------------------+ | user | host | password | +------+-----------+-------------------------------------------+ | root | localhost | *B181A5BCA7C882221F5B8F6F9657AE71FF67EDDB | | root | 127.0.0.1 | *B181A5BCA7C882221F5B8F6F9657AE71FF67EDDB | +------+-----------+-------------------------------------------+ 2 rows in set (0.00 sec) mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) #退出数据库重新连接 [root@httpd ~]# mysql -u root -p -h 127.0.0.1 Enter password: #输入之前设置的mysql数据库密码 Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2 Server version: 5.5.37-log Source distribution 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>
8.最后将mysql添加到开机自动启动
[root@httpd ~]# chkconfig --add mysqld [root@httpd ~]# chkconfig mysqld on [root@httpd ~]# chkconfig mysqld --list mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off
本文出自 “ly36843运维” 博客,请务必保留此出处http://ly36843.blog.51cto.com/3120113/1642561
原文地址:http://ly36843.blog.51cto.com/3120113/1642561