#mysql安装
# 安装工具:
yum -y install gcc-c++ ncurses cmake make ncurses-devel
# 拷贝配置文件到指定目录:
rm -rf /etc/my.cnf
cp -f my.cnf /etc/my.cnf
# 创建mysql用户和组:
groupadd mysql
useradd -r -g mysql -s /bin/false mysql
# 解压安装文件:
tar zxvf mysql-5.6.36.tar.gz
cd mysql-5.6.36
# 指定端口号&数据文件存放路径:
cmake -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DENABLED_LOCAL_INFILE=1 -DMYSQL_DATADIR=/data/mysql_data -DMYSQL_TCP_PORT=3306 # 3306: server listens for TCP/IP connections. The default is 3306.
make && make install
cd /usr/local
cd /usr/local/mysql
chown -R mysql .
mkdir -p /data/mysql_data/{binlog,tmpdir}
chown -R mysql.mysql /data/mysql_data
cd /data/mysql_data
# 数据库的初始化:
/usr/local/mysql/scripts/mysql_install_db --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql --datadir=/data/mysql_data --user=mysql
if [ $? -eq 0 ] ; then
echo "init success !"
fi
# 添加环境变量:
echo "export PATH=$PATH:/usr/local/mysql/bin" >>/etc/profile && source /etc/profile
# 启动mysql服务:
/usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql --datadir=/data/mysql_data &
# 重启mysql服务:
# kill -9 myid;
/usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf &
MySQL (/home/press有装好的MySQL)建用户建库
1、 ps -ef|grep mysql(若已启动mysql,则kill掉进程)
2、 启动:/usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql --datadir=/data/mysql_data &
3、ps -ef|grep mysql (mysql端口为3301),启动mysql之后,输入mysql 回车即可进入mysql
4、查看用户及其权限:select user,host,password from mysql.user;
5、新建press用户并授权:grant all privileges on *.* to press@'%' identified by 'press';
6、用客户端SQLyog新建数据库press(注意此处的字符集为utf8mb4,排序规则为utf8mb4_general_ci)
7、查看数据库:show databases;