Check if mysql is installed:
mysql --version
mysql Ver 14.14 Distrib 5.7.13, for Linux (x86_64) using EditLine wrapper
Check if cmake is installed:
Enter the command: cmake -help
3. Install the cmake package
# wget
# tar zxvf
# cd
/# ./bootstrap
# gmake
# gmake install
4. Create mysql installation directory and database storage directory
# mkdir -p /usr/local/mysql //Install mysql
# mkdir -p /usr/local/mysql/data //Store the database
5. Add users and create database directories and permission settings
#groupadd mysql
#useradd -r -g mysql mysql
6. MYSQL 5.7.13 installation
#cd /usr/local
#wget
#tar zvxf
#mv boost_1_59_0 boost
#cd / opt
#wget http://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.13.tar.gz
# tar zxvf mysql-5.7.13.tar.gz
# cd mysql-5.7.13
# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DSYSCONFDIR=/etc -DMYSQL_TCP_PORT=3306 -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all -DENABLED_LOCAL_INFILE=1 -DWITH_BOOST=/usr/local/boost
# gmake
# gmake install
Parameter Description:
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql //Installation directory
-DINSTALL_DATADIR=/usr/local/mysql/data //Database storage directory
-DDEFAULT_CHARSET=utf8 //Use utf8 characters
-DDEFAULT_COLLATION=utf8_general_ci //check character
-DEXTRA_CHARSETS=all //Install all extended character sets
-DENABLED_LOCAL_INFILE=1 //Allow data to be imported from local
Precautions:
When recompiling, old object files and cache information need to be cleared.
# make clean
# rm -f CMakeCache.txt
# rm -rf /etc/my.cnf
# cd /usr/local/mysql
7. Configuration
(1) Set directory permissions
# cd /usr/local/mysql
# chown -R root:mysql . //Set the owner of all files in the current directory to root and the group to mysql
# chown -R mysql:mysql data
(2) 启动服务添加到系统
# cp support-files/my-default.cnf /etc/my.cnf //将mysql的启动服务添加到系统服务中
(3)创建系统数据库的表
# cd /usr/local/mysql
# ./bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
(4)设置环境变量
# vi /root/.bash_profile
在PATH=$PATH:$HOME/bin添加参数为:
PATH=$PATH:$HOME/bin:/usr/local/mysql/bin:/usr/local/mysql/lib
#source /root/.bash_profile
(5)启动mysql
# cd /usr/local/mysql
# cp support-files/mysql.server /etc/init.d/mysql //将mysql的启动服务添加到系统服务中
# chkconfig --add mysql # 添加到系统服务
# chkconfig mysql on # 开机启动
# service mysql start
# ln -s /usr/local/mysql/bin/mysql /usr/bin
————————设置账号————————————
[root@gj mysql]# mysql -u root -p
Enter password: 初始密码为空,回车
mysql> set password for root@localhost = password('123456');
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> update user set host = '%' where user = 'root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> select host, user from user;
+-----------+-----------+
| host | user |
+-----------+-----------+
| % | root |
| localhost | mysql.sys |
+-----------+-----------+
2 rows in set (0.00 sec)
set global max_allowed_packet = 2*1024*1024*10;
------------------------------------------安全设置--------------------------------------
创建数据库:
create database 数据库名 default charset utf8 collate utf8_general_ci;
创建一个最小权限的用户test
create user 'test'@'%' IDENTIFIED by '123456';
grant select,insert,update,delete,create,drop,alter on 数据库名.* to 'test'@'%';
grant lock tables on 数据库名.* to 'test'@'%';
flush privileges;
修改root用户名和密码,限制远程访问
update mysql.user set user="admin" where user="root";
flush privileges;
update user set host='localhost' where user='admin';
flush privileges;//只允许root在本机登录
SET PASSWORD FOR 'admin'@'localhost' = PASSWORD('复杂的密码');
flush privileges;