-
1.添加mysql用户组
- groupadd mysql
-
2.添加mysql用户
- useradd -g mysql -s /bin/nologin mysql -M
- 3.查看系统中是否安装mysql,如果安装需要卸载.rpm -e --nodeps 命令来卸载掉
[root@backend-cxy mysql]# rpm -qa | grep mysql
mysql-libs-5.1.73-8.el6_8.x86_64
[root@backend-cxy mysql]# rpm -e mysql-libs-5.1.73-8.el6_8.x86_64 --nodeps
- 4.安装依赖包
- yum -y install wget gcc-c++ ncurses-devel cmake
- 进入http://dev.mysql.com/downloads/mysql/,选择Source Code下的Generic Linux。选择带boost库的mysql下载。MySQL5.7对boost库有要求,选择带boost库的会避过一些坑。
wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-boost-5.7.20.tar.gz
- 5.解压、编译
- CMAKE_INSTALL_PREFIX:指定MySQL程序的安装目录,默认/usr/local/mysql
- DEFAULT_CHARSET:指定服务器默认字符集,默认latin1
- DEFAULT_COLLATION:指定服务器默认的校对规则,默认latin1_general_ci
- ENABLED_LOCAL_INFILE:指定是否允许本地执行LOAD DATA INFILE,默认OFF
- WITH_COMMENT:指定编译备注信息
- WITH_xxx_STORAGE_ENGINE:指定静态编译到mysql的存储引擎,MyISAM,MERGE,MEMBER以及CSV四种引擎默认即被 编译至服务器,不需要特别指定。
- WITHOUT_xxx_STORAGE_ENGINE:指定不编译的存储引擎
- SYSCONFDIR:初始化参数文件目录
- MYSQL_DATADIR:数据文件目录
- MYSQL_TCP_PORT:服务端口号,默认3306
- MYSQL_UNIX_ADDR:socket文件路径,默认/tmp/mysql.sock
tar xf mysql-boost-5.7.18.tar.gz
cd mysql-5.7.18
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1 -DMYSQL_USER=mysql -DMYSQL_TCP_PORT=3306 -DWITH_BOOST=boost/boost_1_59_0
make && make install
- 6.编译完后,MySQL会安装到/usr/local/mysql目录。进入该目录并创建data目录
cd /usr/local/mysql
mkdir data
- 7.修改目录权限
chown -R mysql. /usr/local/mysql
- 8.初始化数据库
- 之前版本mysql_install_db是在mysql_basedir/script下,5.7放在了mysql_install_db/bin目录下,且已被废弃
- "--initialize"会生成一个随机密码(~/.mysql_secret),而"--initialize-insecure"不会生成密码
- --datadir目标目录下不能有数据文件
- 使用--initialize参数后,一定要记住生成的密码,否则无法登陆数据库。
[root@backend-cxy ]#cd ./bin
[root@backend-cxy bin]# ./mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
2017-09-05T15:03:41.067600Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2017-09-05T15:03:41.338120Z 0 [Warning] InnoDB: New log files created, LSN=45790
2017-09-05T15:03:41.369521Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2017-09-05T15:03:41.426215Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 6778cd1c-924b-11e7-a8c2-0050569e3837.
2017-09-05T15:03:41.426860Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2017-09-05T15:03:41.429970Z 1 [Note] A temporary password is generated for root@localhost: rU?Dow;aA8oF
- 9.拷贝启动文件到/etc/init.d/下并重命令为mysqld
/usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
- 10.安装完后发现没有my.cnf配置文件,手动创建个
# vim /etc/my.cnf
[mysqld]
basedir =/usr/local/mysql
datadir =/usr/local/mysql/data
port = 3306
socket = /tmp/mysql.sock
[client]
socket=/tmp/mysql.sock
- 11.启动MySQL
/etc/init.d/mysqld start
- 12.登录MySQL
/usr/local/mysql/bin/mysql -uroot -p系统生成的密码
- 13.修改root密码
mysql>set password = password(‘Newpassword‘);
mysql>flush privileges;
mysql>exit
- 14.退出重新登录
/usr/local/mysql/bin/mysql -uroot -p‘Newpassword'
- 15.查看安装状态
rpm -qi mysql-server
service mysqld start
- 16.查看是否开机启动
[root@xiaoluo ~]# chkconfig --list | grep mysqld
mysqld 0:关闭 1:关闭 2:关闭 3:关闭 4:关闭 5:关闭 6:关闭
[root@xiaoluo ~]# chkconfig mysqld on <---开机启动
[root@xiaoluo ~]# chkconfig --list | grep mysql
mysqld 0:关闭 1:关闭 2:启用 3:启用 4:启用 5:启用 6:关闭
- 17.必须初始化密码,不然链接不上
mysql> set password = password("steve201718");
mysql> flush privileges;
mysql> exit
/usr/local/mysql/bin/mysql -uroot -p NewPassword
[root@backend-cxy]# ln -s /usr/local/mysql/bin/mysql /usr/bin
[root@backend-cxy bin]# mysql -p
Enter password:
- 授权root用户使用'NewPassword'从任何机器链接数据库
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'NewPassword' WITH GRANT OPTION;
- 关闭防火墙
/etc/init.d/iptables stop
- 查看mysql服务是否起来
[root@backend-cxy bin]# netstat -antp | grep 3306
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 :::3306 :::* LISTEN 20723/mysqld
- 查看链接状态
[root@backend-cxy log]# netstat -anp | grep 3306
tcp 0 0 :::3306 :::* LISTEN 20723/mysqld
tcp 0 0 ::ffff:192.168.0.13:3306 ::ffff:192.168.1.55:59516 ESTABLISHED 20723/mysqld
tcp 0 0 ::ffff:192.168.0.13:3306 ::ffff:192.168.1.55:59248 ESTABLISHED 20723/mysqld
- 创建mysql用户
CREATE USER demo IDENTIFIED BY “123456”
- 授权该用户
允许用户jack从ip为10.10.50.127的主机连接到mysql服务器,并使用654321作为密码
mysql>GRANT ALL PRIVILEGES ON *.* TO 'jack'@’10.10.50.127’ IDENTIFIED BY '654321' WITH GRANT OPTION;
mysql>GRANT ALL PRIVILEGES ON shandong.* TO 'demo'@'%'WITH GRANT OPTION
网友评论