Linux安装MySQL

[code="java"]
http://blog.csdn.net/wb96a1007/article/details/51559741


查看mysql连接数
netstat -an | grep 8080|wc -l

导出
./mysqldump -uroot -proot db_yy_recover > ./db_yy_recover.sql

复制
scp ./db_account.sql [email protected]:/var/lib/mysql

恢复
mysql -uroot -proot;
mysql -u root -p db_account < db_account.sql

创建数据库
create database db_yy_recover charset utf8;

更新数据库字符集
alter database db_message charset utf8mb4;

安装MySQL 5.7.9(安装用户root, 目标目录/opt/mysql)

1 查看安装
rpm -qa | grep mysql

2 移除安装
rpm -e mysql-libs-5.1.73-7.el6.x86_64 --nodeps

3 安装
bin/mysql_install_db --user=mysql --basedir=/opt/mysql/ --datadir=/opt/mysql/data/

4 复制配置文件
# cp -a ./support-files/my-default.cnf /etc/my.cnf
# cp -a ./support-files/mysql.server /etc/init.d/mysqld

5 修改配置文件
如果改变默认安装路径,则需要
1)/etc/my.cnf、/etc/init.d/mysqld中修改
basedir='/apps/mysql'
datadir='/apps/mysql/data'
2)创建ln
mkdir -p /usr/local/mysql/bin
ln -s /apps/mysql/bin/mysqld /usr/local/mysql/bin/mysqld

6 启动
cd /opt/mysql/bin
./mysqld_safe --user=mysql &

/etc/init.d/mysqld restart

设置开机启动
chkconfig --level 35 mysqld on

查看初始密码
cat /root/.mysql_secret
# Password set for user 'root@localhost' at 2016-12-28 09:31:17
;c2Yhshz6l7>

重置密码
./mysql -uroot -p

mysql>SET PASSWORD = PASSWORD('123456');

mysql>flush privileges;

mysql>use mysql;

mysql>update user set host = '%' where user = 'root';

mysql>select host, user from user;

mysql>flush privileges;

mysql>quit;

重启MySQL
/etc/init.d/mysqld restart

[/code]

你可能感兴趣的:(mysql,数据库,java)