2019独角兽企业重金招聘Python工程师标准>>>
在http://dev.mysql.com/downloads/mysql/页面选择Source Code下载mysql-5.5.48.tar.gz
如果不是选择Source Code在安装的时候会报如下错误:
CMake Error: The source directory “*” does not appear to contain CMakeLists.txt.
Specify –help for usage, or press the help button on the CMake GUI.
1.安装所需相关库文件:
# yum install -y gcc gcc-c++ gcc-g77 autoconf automake zlib* fiex* libxml* ncurses-devel libmcrypt* libtool-ltdl-devel* cmake make
2.安装过程
(1)创建目录、用户和权限
# mkdir -p /usr/local/mysql #建立mysql安装目录
# mkdir -p /usr/local/mysql/data #建立mysql数据库目录
# groupadd mysql #添加mysql组
# useradd -g mysql mysql #添加一个mysql用户并加入到mysql组中
# chown -R mysql.mysql /usr/local/mysql/data/ #将/data/mysql目录的所有权赋予mysql组中的mysql用户
(2)安装mysql
上传mysql-5.5.48.tar.gz至/usr/local/src/
进入目录:# cd /usr/local/src/
# tar -zxvf mysql-5.5.48.tar.gz
# cd mysql-5.5.48
# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_UNIX_ADDR=/usr/local/mysql/data/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS:STRING=all -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1 -DMYSQL_DATADIR=/usr/local/mysql/data/ -DMYSQL_USER=mysql -DMYSQL_TCP_PORT=3306
# make && make install
# cp /usr/local/mysql/support-files/my-medium.cnf /etc/my.cnf #如果你的机器的内存较大,可以复制My-huge.cnf文件
# chmod 755 scripts/mysql_install_db
# scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data/ ##初始化数据库
# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql #设置开机启动mysql
# chmod 755 /etc/init.d/mysql
# chkconfig mysql on #开机启动
# echo 'export PATH=/usr/local/mysql/bin:$PATH' >> /etc/profile #将mysql的安装路径加入PATH
# source /etc/profile #使配置立即生效
# /etc/init.d/mysql start #启动mysql(如启动后不能登录,则重启系统)
# netstat -nat | grep 3306 #查看3306端口是否打开
(3)防火墙开放3306端口
# vim /etc/sysconfig/iptables
添加
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
重启防火墙服务
(4)设置和修改root用户密码
mysql修改,可在mysql命令行执行如下:
[root@localhost ~]# mysql -u root -p //首次登录可使用[root@localhost ~]# mysql
mysql> use mysql;
mysql> update user set password= password ("root") where user='root';
mysql> update user set password= password ("root");(用这句)
(5)开启允许远程连接
mysql> select `Host`,`User` from user;
mysql> update user set `Host` = '%' where `User` = 'root' limit 1;
mysql> quit
注意在mysql 命令行形式下一定要输入";"
重启一下mysql服务,
# /etc/init.d/mysql restart