首先规划好
端口:3306
管理员名称:cool
安装基本目录:/usr/local/mysql
数据库目录:/data
二进制日志目录:/var/log/mysqld
延迟日志目录:/var/log/mysqld(延迟日志目录 这个还不怎么明白)
启动文件:/var/run/mysqld
添加mysql用户
#groupadd -r mysql
# useradd -r -g mysql -s /sbin/nologin mysql
#cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS=complex -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DWITH_SSL=yes -DWITH_EMBEDDED_SERVER=1 -DENABLED_LOCAL_INFILE=1 -DMYSQL_DATADIR=/data -DMYSQL_TCP_PORT=3306
ENABLED_LOCAL_INFILE 是否开启客户端本地存储以减轻数据库的负载
#make
#make install
#ln -s /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
#ln -s /usr/local/mysql/bin/mysql /bin/mysql
删除空密码、匿名的用户
mysql> delete from mysql.user where password='';
mysql> delete from mysql.user where user='';
mysql> flush privileges;
创建数据库管理帐户,允许远程用户访问。并将root更名为其他名称
mysql> CREATE USER 'cool'@'%' IDENTIFIED BY '123456';
mysql> GRANT ALL ON *.* TO 'cool'@'%' WITH GRANT OPTION;
mysql> RENAME USER 'root'@'localhost' TO 'cool'@'localhost';
mysql> flush privileges;
安全
除了管理员帐号外,不要把file, process, super,reload,shutdown,grant权限授予管理员以外的账号
update mysql.user set file_priv = 'N' Where User=user_name and host =
host_name
update mysql.user set process_priv = 'N' Where User=user_name and host =
host_name
update mysql.user set super_priv = 'N'Where User=user_name and host =
host_name
update mysql.user set reload_priv = 'N' Where User=user_name and host =
host_name
update mysql.user set shutdown_priv = 'N' Where User=user_name and host =
host_name
update mysql.user set grant_priv = 'N' Where User=user_name and host =
host_name