MySQL5.5.54安装[二进制方式]

环境准备

主机名称 IP地址
mysql 192.168.200.9
echo "192.168.200.9 mysql ">>/etc/hosts
  • 操作系统信息
[root@hadoop-master ~]# uname -r
2.6.32-358.el6.x86_64
[root@hadoop-master ~]# uname -m
x86_64
[root@hadoop-master ~]# cat /etc/redhat-release 
CentOS release 6.4 (Final)
[root@hadoop-master ~]# getenforce 
Disabled

创建MySQL用户

useradd mysql -s /sbin/nologin -M
id mysql

安装MySQL

  • 下载
    MySQL下载地址
    下载慢,可以使用迅雷下载
  • 安装
tar zxvf mysql-5.5.54-linux2.6-x86_64.tar.gz
mkdir /application
mv mysql-5.5.54-linux2.6-x86_64 /application/mysql-5.5.54
ln -s /application/mysql-5.5.54/ /application/mysql
ll /application/
chown -R mysql:mysql /application/mysql*

初始化数据库

[root@mysql mysql]# /application/mysql/scripts/mysql_install_db --basedir=/application/mysql --datadir=/application/mysql/data/ --user=mysql

初始化信息:

Installing MySQL system tables...
170903 15:54:08 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
170903 15:54:08 [Note] /application/mysql/bin/mysqld (mysqld 5.5.54) starting as process 3137 ...
OK
Filling help tables...
170903 15:54:08 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
170903 15:54:08 [Note] /application/mysql/bin/mysqld (mysqld 5.5.54) starting as process 3144 ...
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 mysql 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 at http://bugs.mysql.com/

修改数据库配置文件

mysql默认配置文件是/etc/my.cnf,备份原有的

mv /etc/my.cnf /etc/my.cnf.default-backup

使用较小的配置:

[root@mysql support-files]# cp /application/mysql/support-files/my-small.cnf /etc/my.cnf

启动MySQL

修改启动mysql脚本

由于二进制默认安装目录在/usr/local下,而我们将自定义将mysql安装在/application/下,因此需要修改启动脚本
测试:

[root@mysql support-files]# sed -n "s#/usr/local/mysql#/application/mysql#pg" /application/mysql/bin/mysqld_safe

替换:

sed -i "s#/usr/local/mysql#/application/mysql#g" /application/mysql/bin/mysqld_safe

启动mysql

/application/mysql/bin/mysqld_safe &

MySQL常用优化设置

设置密码

/application/mysql/bin/mysqladmin -u root password '123456'

配置环境变量

echo 'export PATH=/application/mysql/bin:$PATH' >> /etc/profile&&source /etc/profile&&tail -1 /etc/profile

加入到/etc/init.d/下

cp /application/mysql/support-files/mysql.server /etc/init.d/mysqld
sed -i "s#/usr/local/mysql#/application/mysql#g" /etc/init.d/mysqld 
chmod +x /etc/init.d/mysqld 

测试启动

killall mysqld
mysqld: no process killed
[root@mysql sbin]# /etc/init.d/mysqld start
Starting MySQL.. SUCCESS! 
[root@mysql sbin]# lsof -i :3306

加入开机启动

[root@mysql sbin]# chkconfig --add mysqld
[root@mysql sbin]# chkconfig mysqld --list
mysqld          0:off   1:off   2:on    3:on    4:on    5:on    6:off

MySQL日志

ll /application/mysql/data/mysql.err

MySQL字符集

  • 修改服务器级别字符集
    打开/etc/mysql/my.cnf,在[mysqld]后添加
character-set-server=utf8
  • 更改连接字符集
    打开/etc/mysql/my.cnf,在[client]后添加
default-character-set=utf8

你可能感兴趣的:(MySQL5.5.54安装[二进制方式])