-
下载mysql源码mysql-5.5.17.tar.gz http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.22.tar.gz/from/http://cdn.mysql.com/
-
yum方式安装相关依赖包 yum -y install cmake bison git ncurses-devel gcc gcc-c++
-
创建一个用户名为mysql的用户并加入mysql用户组
# groupadd mysql
# useradd -g mysql mysql
-
解压mysql-5.6.38.tar.gz,并且创建mysql安装目录和数据库文件存放目录
# tar zxvf mysql-5.6.38.tar.gz
# mkdir /usr/local/mysql
# mkdir /usr/local/mysql/data
# cd mysql-5.6.38/
# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DMYSQL_DATADIR=/usr/local/mysql/data -DMYSQL_TCP_PORT=3306 -DMYSQL_USER=mysql -DENABLE_DOWNLOADS=1
-
进入/mysql目录执行
make && make install
-
修改目录属主权限
# chown -R mysql:mysql /usr/local/mysql/data/
# chown -R mysql:mysql /usr/local/mysql/
-
创建MySQL Server系统表
# cd /usr/local/mysql/
# scripts/mysql_install_db --user=mysql --datadir=/usr/local/mysql/data
-
配置启动脚本
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
-
添加配置文件
vim /etc/my.cnf
[mysql] # 设置mysql客户端默认字符集 default-character-set=utf8 socket=/var/lib/mysql/mysql.sock [mysqld] skip-name-resolve #设置3306端口 port = 3306 socket=/var/lib/mysql/mysql.sock # 设置mysql的安装目录 basedir=/usr/local/mysql # 设置mysql数据库的数据的存放目录 datadir=/usr/local/mysql/data # 允许最大连接数 max_connections=200 # 服务端使用的字符集默认为8比特编码的latin1字符集 character-set-server=utf8 # 创建新表时将使用的默认存储引擎 default-storage-engine=INNODB lower_case_table_names=1 max_allowed_packet=16M #忘记密码时可取消注释,无密码登陆 #skip-grant-tables
-
添加环境变量
vim /etc/profile export MYSQL_HOME=/usr/local/mysql export PATH=.:$MYSQL_HOME/bin:$PATH source /etc/profile 设置开机启动: chkconfig mysqld on 启动服务: service mysqld start
-
设置初始密码
1、使用空的初始密码登录mysql账号: mysql-uroot -p 2、修改root密码: mysql> update user set Password=password("123456") where User='root'; Query OK, 4 rows affected (0.01 sec) Rows matched: 4 Changed: 4 Warnings: 0 mysql> flush privileges; Query OK, 0 rows affected (0.04 sec) mysql> select Host,User,password from user where user='root'; +-----------------------+------+-------------------------------------------+ | Host | User | password | +-----------------------+------+-------------------------------------------+ | localhost | root | *5626ED34B75C6C508BA2A3D0A4F6E4C58823138C | | localhost.localdomain | root | *5626ED34B75C6C508BA2A3D0A4F6E4C58823138C | | 127.0.0.1 | root | *5626ED34B75C6C508BA2A3D0A4F6E4C58823138C | | ::1 | root | *5626ED34B75C6C508BA2A3D0A4F6E4C58823138C | +-----------------------+------+-------------------------------------------+ 4 rows in set (0.00 sec)