1.安装cmake
yum -y install cmake
2.将mysql安装包剪切到/usr/local/src下
3.解压
4.cmake
cmake
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql
-DMYSQL_DATADIR=/usr/local/mysql/data
-DSYSCONFDIR=/etc
-DWITH_MYISAM_STORAGE_ENGINE=1
-DWITH_INNOBASE_STORAGE_ENGINE=1
-DWITH_MEMORY_STORAGE_ENGINE=1
-DWITH_READLINE=1
-DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock
-DMYSQL_TCP_PORT=3306
-DENABLED_LOCAL_INFILE=1
-DWITH_PARTITION_STORAGE_ENGINE=1
-DEXTRA_CHARSETS=all
-DDEFAULT_CHARSET=utf8
-DDEFAULT_COLLATION=utf8_general_ci
linux安装mysql出现Could NOT find Curses (missing CURSES_LIBRARY CURSES_INCLUDE_PATH),提示解决方法
rm CMakeCache.txt
yum install ncurses-devel
yum install gcc-c++
5.make && make install
6.添加用户
[root@localhost tmp]# groupadd mysql
[root@localhost tmp]# useradd -g mysql mysql
7.修改权限
chown -R mysql:mysql /usr/local/mysql
8.初始化数据库,创建系统自带的数据库和表
scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql
注:在启动MySQL服务时,会按照一定次序搜索my.cnf,先在/etc目录下找,找不到则会搜索"$basedir/my.cnf",在本例中就是 /usr/local/mysql/my.cnf,这是新版MySQL的配置文件的默认位置!
注意:在CentOS 7版操作系统的最小安装完成后,在/etc目录下会存在一个my.cnf,需要将此文件更名为其他的名字,如:/etc/my.cnf.bak,否则,该文件会干扰源码安装的MySQL的正确配置,造成无法启动。
find / -name my.cnf
9.配置mysql服务
[root@localhost mysql]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
[root@localhost mysql]# chkconfig mysql on
[root@localhost mysql]# service mysql start --启动MySQL
有可能会失败,进行下面的处理
[root@localhost etc]# mkdir -p /var/lib/mysql
[root@localhost etc]# chown mysql:mysql /var/lib/mysql
10.修改登录密码
/usr/local/mysql/bin/mysqld_safe --user=mysql &
mysql>use mysql; 选择数据库
Database changed
mysql> UPDATE user SET password=PASSWORD("新密码") WHERE user='你的用户名';
mysql> FLUSH PRIVILEGES;
mysql> quit;
mysql> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> UPDATE user SET password=PASSWORD("123456") WHERE user='root';
Query OK, 4 rows affected (0.03 sec)
Rows matched: 4 Changed: 4 Warnings: 0
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
mysql> quit;
11.设置外部访问
mysql> grant all privileges on *.* to root@"192.168.1.88" identified by "123456";
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> select user,host from user;