|
准备编译环境 因为我的Linux是刚安装的,需要安装很多的必要程序。 1
2
| yum -y installmakegcc-c++ cmake bison-devel ncurses-devel gcc\
autoconf automake zlib* fiex* libxml* libmcrypt* libtool-ltdl-devel*
| 下载MySQL编译源码接下来组织项目 01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
| cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql\
-DMYSQL_DATADIR=/data/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=/tmp/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
|
有时候会出现类似的问题。 Googlemock was not found. gtest-based unit tests will be disabled. You can run cmake . -DENABLE_DOWNLOADS=1 to automatically download and build required components from source. — If you are inside a firewall, you may need to use an http proxy: export http_proxy=http://example.com:80 - 使用参数-DENABLE_DOWNLOADS=1 自动下载。
- 有网络限制,设置http代理export http_proxy=http://example.com:80。环境变量http_proxy 也为 curl 等其他工具所用。尽管 yum 可以识别大写或小写的 http_proxy,但curl 要求环境变量的名称是小写。
如果这个cmake这个步骤有出现问题,解决后重新再cmake一次。如果输出类似这样,那么就好了。 01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
| -- Running cmake version 2.6.4
-- MySQL 5.6.16
-- Packaging as: mysql-5.6.16-Linux-x86_64
-- HAVE_VISIBILITY_HIDDEN
-- HAVE_VISIBILITY_HIDDEN
-- HAVE_VISIBILITY_HIDDEN
-- Using cmake version 2.6.4
-- Not building NDB
-- Library mysqlclient depends on OSLIBS -lpthread;m;rt;dl
-- GMOCK_SOURCE_DIR:/root/mysql-5.6.16/source_downloads/gmock-1.6.0
-- GTEST_LIBRARIES:gmock;gtest
-- Library mysqlserver depends on OSLIBS -lpthread;m;rt;crypt;dl
-- Configuring done
-- Generating done
-- Build files have been written to: /root/mysql-5.6.16
|
接着编译源码
编译时间缓慢,等待中…
修改文件权限,生成数据库
- groupadd mysql
- useradd -r -g mysql mysql
- cd /usr/local/mysql
- chown -R mysql:mysql .
- scripts/mysql_install_db --user=mysql --ldata=/data/mysql/data
- chown -R root .
- chown -R mysql data
说明:参数--ldata说明你的数据文件存放的目录,如果你使用默认的路径,那么这个参数可以去除。如果你不增加此参数,但是在配置文件(见下方的datadir配置)中指定了其他的目录,那么会在启动MySQL的时候出现类似的提示: Starting MySQL. ERROR! The server quit without updating PID file (/data/mysql/data/VM_208.pid). 出现这个的解决办法就是增加--ldata参数,指定和配置文件中datadir相同的值,重新执行mysql_install_db即可。
设置配置文件(替换my.conf)MySQL 5.6.8开始,就不在分发my.cnf等配置的demo,所以想随便拿一个用都比较麻烦。 my.cnf的配置文件的默认读取顺序为
FILE NAME(上面的优先)PURPOSE
/etc/my.cnfGlobal options
/etc/mysql/my.cnfGlobal options
SYSCONFDIR/my.cnfGlobal options
$MYSQL_HOME/my.cnfServer-specific options
defaults-extra-fileThe file specified with --defaults-extra-file=path, if any
~/.my.cnfUser-specific options
~/.mylogin.cnfLogin path options01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
| [client]
port=3306
socket=/var/lib/mysql/mysql.sock
default-character-set = utf8
[mysqld]
port=3306
bind-address=127.0.0.1
basedir=/usr/local/mysql
datadir=/data/data/mysql/data
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
############# default settings ################
# time zone
default-time-zone = system
character-set-server = utf8
default-storage-engine = InnoDB
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
|
启动MySQL,开机自动启动设置 手动启动MySQL。 1
2
3
4
| cp/usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
/etc/init.d/mysqlstart
##或者
service mysql start
|
在上面的步骤后,开机自动启动设置 1
2
3
| chkconfig --add mysql
##有的系统需要下面的
chkconfig --level 345 mysql on
| 修改root密码默认的密码是空的,很危险,需要修改一下。 在此之前,为方便调用mysql,我们先生成一个mysql的软链。 1
| ln-s /usr/local/mysql/bin/mysql/usr/bin/
|
然后修改密码 1
2
| mysql -uroot -h127.0.0.1 -p
mysql> SET PASSWORD = PASSWORD('trsadmin');
|
- 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
- update user set host = '%' where user = 'root';
更改下表内权限
- select host, user from user;
查看
+-----------+------+
| host | user |
+-----------+------+
| % | root |
| 127.0.0.1 | root |
| ::1 | root |
| demo | |
| demo | root |
| localhost | |
+-----------+------+
通过上面的步骤,就可以使用MySQL数据库了,另外可以为mysql安装phpmyadmin作为前端的管理界面。
打开root远程访问改表法。可能是你的帐号不允许从远程登陆,只能在localhost。这个时候只要在localhost的那台电脑,登入mysql后,更改 "mysql" 数据库里的 "user" 表里的 "host" 项,从"localhost"改称"%"
CODE:mysql -u root -p123
mysql>use mysql;
mysql>update user set host = '%' where user = 'root';
mysql>select host, user from user;
运行完最后一句话后出了个错误ERROR 1062 (23000): Duplicate entry '%-root' for key 'PRIMARY'
于是又去找解决方案,发现先
mysql> select host from user where user = 'root';
+-----------------------+
| host |
+-----------------------+
| % |
| 127.0.0.1 |
| localhost.localdomain |
+-----------------------+
3 rows in set (0.00 sec)
host已经有了%这个值,所以直接运行命令:
mysql>flush privileges;
|